MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / isMatch

Method isMatch

44-Wildcard-Matching/44-Wildcard-Matching.cpp:3–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2public:
3 bool isMatch(string s, string p) {
4 int m = s.length(), n = p.length();
5 int i = 0, j = 0, asterick = -1, match;
6 while (i < m) {
7 if (j < n && p[j] == '*') {
8 match = i;
9 asterick = j++;
10 }
11 else if (j < n && (s[i] == p[j] || p[j] == '?')) {
12 i++;
13 j++;
14 }
15 else if (asterick >= 0) {
16 i = ++match;
17 j = asterick + 1;
18 }
19 else return false;
20 }
21 while (j < n && p[j] == '*') j++;
22 return j == n;
23 }
24};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected