We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2bcf6d6 commit 6d2a2d3Copy full SHA for 6d2a2d3
44-wildcard-matching.js
@@ -0,0 +1,34 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {string} p
4
+ * @return {boolean}
5
+ */
6
+const isMatch = function(s, p) {
7
+ const M = s.length
8
+ const N = p.length
9
+ let i = 0,
10
+ j = 0,
11
+ lastMatchInS,
12
+ lastStarPos
13
+ while (i < M) {
14
+ if (j < N && (p[j] === s[i] || p[j] === '?')) {
15
+ i++
16
+ j++
17
+ } else if (j < N && p[j] === '*') {
18
+ lastStarPos = j
19
20
+ lastMatchInS = i
21
+ } else if (lastStarPos !== undefined) {
22
+ // back to previous step
23
+ j = lastStarPos + 1
24
+ lastMatchInS++
25
+ i = lastMatchInS
26
+ } else {
27
+ return false
28
+ }
29
30
+ while (j < N && p[j] === '*') {
31
32
33
+ return j === N
34
+}
0 commit comments