File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed 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+ } ;
Original file line number Diff line number Diff line change 494941|[ First Missing Positive] ( ./0041-first-missing-positive.js ) |Hard|
505042|[ Trapping Rain Water] ( ./0042-trapping-rain-water.js ) |Hard|
515143|[ Multiply Strings] ( ./0043-multiply-strings.js ) |Medium|
52+ 44|[ Wildcard Matching] ( ./0044-wildcard-matching.js ) |Hard|
525345|[ Jump Game II] ( ./0045-jump-game-ii.js ) |Medium|
535446|[ Permutations] ( ./0046-permutations.js ) |Medium|
545547|[ Permutations II] ( ./0047-permutations-ii.js ) |Medium|
You can’t perform that action at this time.
0 commit comments