File tree 2 files changed +51
-0
lines changed
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 49
49
41|[ First Missing Positive] ( ./0041-first-missing-positive.js ) |Hard|
50
50
42|[ Trapping Rain Water] ( ./0042-trapping-rain-water.js ) |Hard|
51
51
43|[ Multiply Strings] ( ./0043-multiply-strings.js ) |Medium|
52
+ 44|[ Wildcard Matching] ( ./0044-wildcard-matching.js ) |Hard|
52
53
45|[ Jump Game II] ( ./0045-jump-game-ii.js ) |Medium|
53
54
46|[ Permutations] ( ./0046-permutations.js ) |Medium|
54
55
47|[ Permutations II] ( ./0047-permutations-ii.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 44. Wildcard Matching
3
+ * https://leetcode.com/problems/wildcard-matching/
4
+ * Difficulty: Hard
5
+ *
6
+ * Given an input string (s) and a pattern (p), implement wildcard pattern
7
+ * matching with support for '?' and '*' where:
8
+ *
9
+ * - '?' Matches any single character.
10
+ * - '*' Matches any sequence of characters (including the empty sequence).
11
+ *
12
+ * The matching should cover the entire input string (not partial).
13
+ */
14
+
15
+ /**
16
+ * @param {string } s
17
+ * @param {string } p
18
+ * @return {boolean }
19
+ */
20
+ var isMatch = function ( s , p ) {
21
+ let i = 0 ;
22
+ let j = 0 ;
23
+ let start = - 1 ;
24
+ let offset = - 1 ;
25
+
26
+ while ( i < s . length ) {
27
+ if ( j < p . length && s [ i ] === p [ j ] || p [ j ] === '?' ) {
28
+ i ++ ;
29
+ j ++ ;
30
+ } else if ( j < p . length && p [ j ] === '*' ) {
31
+ start = j ;
32
+ offset = i ;
33
+ j ++ ;
34
+ } else if ( start === - 1 ) {
35
+ return false ;
36
+ } else {
37
+ j = start + 1 ;
38
+ i = offset + 1 ;
39
+ offset = i ;
40
+ }
41
+ }
42
+
43
+ for ( let index = j ; index < p . length ; index ++ ) {
44
+ if ( p [ index ] !== '*' ) {
45
+ return false ;
46
+ }
47
+ }
48
+
49
+ return true ;
50
+ } ;
You can’t perform that action at this time.
0 commit comments