leetcode

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

commit 12914f91e64c4550b90595ec1a23f7e489b376fd
parent 4394fc6e1ed9d57e852cfbad3a2fa33156a811c6
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu, 23 Mar 2023 21:07:19 +0100

Random Problem

Diffstat:
AProblems/0044.cpp | 21+++++++++++++++++++++
MREADME.md | 1+
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) |