leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit12914f91e64c4550b90595ec1a23f7e489b376fd
parent4394fc6e1ed9d57e852cfbad3a2fa33156a811c6
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateThu, 23 Mar 2023 20:07:19 +0100

Random Problem

Diffstat:
AProblems/0044.cpp|+++++++++++++++++++++
MREADME.md|+

2 files changed, 22 insertions(+), 0 deletions(-)


diff --git a/Problems/0044.cpp b/Problems/0044.cpp

@@ -0,0 +1,21 @@

class Solution {
public:
bool isMatch(string s, string p) {
int i = 0, j = 0, n = s.size(), m = p.size();
int last = -1, star = -1;
while (i < n) {
if (j < m && (s[i] == p[j] || p[j] == '?'))
i++, j++;
else if (j < m && p[j] == '*') {
star = j++;
last = i;
} else if (star != -1) {
j = star + 1;
i = ++last;
} else
return false;
}
while (p[j] == '*' && j < m) j++;
return j == m;
}
};

diff --git a/README.md b/README.md

@@ -60,6 +60,7 @@ for solving problems.

| 0040 | Medium | [Combination Sum II](Problems/0040.cpp) |
| 0042 | Medium | [Trapping Rain Water](Problems/0011.cpp) |
| 0043 | Medium | [Multiply Strings](Problems/0043.cpp) |
| 0044 | Hard | [Wildcard Matching](Problems/0044.cpp) |
| 0045 | Medium | [Jump Game II](Problems/0045.cpp) |
| 0046 | Medium | [Permutations](Problems/0046.cpp) |
| 0047 | Medium | [Permutations II ](Problems/0047.cpp) |