id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "static int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n return 0;\n}();\n\nclass Solution {\npublic:\n bool isPalindrome(int x) {\n if (x < 0){\n return false;\n }\n\n string num = to_string(x);\n int len = num.length();... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\n auto toDigit(int x) {\n auto copy = x;\n std::vector<char> v;\n while (copy >= 10) {\n v.push_back(copy % 10);\n copy = copy / 10;\n }\n v.push_back(copy % 10);\n return v;\n}\npublic:\n bool isPalindrome(int x) {\n if(x<0)\n return... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x < 0)\n {\n return false;\n }\n\n std::vector<short> digits;\n long pow10 = 1;\n while (x > 0)\n {\n int rem = x % (pow10*10);\n x -= rem;\n digits.p... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "#include <vector>\n\nclass Solution {\npublic:\n bool isPalindrome(int x) {\n if(x < 0) return false;\n\n std::vector<short short> digits;\n \n while(x > 0)\n {\n digits.push_back(x%10);\n x/=10;\n }\n\n int j = digits.size()-1;\n ... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string z = std::to_string(x);\n string y(z.rbegin(), z.rend());\n cout << x << \" \" << y << endl;\n\n return z == y;\n}\n};",
"memory": "11300"
} |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string original = to_string(x);\n string reversed = string(original.rbegin(), original.rend());\n return original == reversed;\n }\n};\n \n \n",
"memory": "11400"
} |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution \n{\npublic:\n bool isPalindrome(int x) \n {\n std::string temp{};\n std::string num = std::to_string(x);\n for (int i = 0; i < num.length();i++)\n {\n temp += num[num.length()-1 - i];\n\n }\n if (temp == num)\n return tru... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "#include <string>\n\nclass Solution {\npublic:\n bool isPalindrome(int x) {\n // Negative numbers are not palindromes\n if (x < 0) return false;\n \n // Convert the integer to a string\n std::string s = std::to_string(x);\n \n // Check if the string is eq... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x < 0) {\n return false;\n }\n else {\n std::string s = std::to_string(x);\n return s == std::string(s.rbegin(), s.rend());\n }\n\n \n }\n};",
"memory": "11500"
} |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n\n if (x < 0)\n {\n return false;\n }\n //int digits = int(log10(x));\n int CheckNum = 1;\n std::string num2str;\n num2str = to_string(x);\n int digits = num2str.length();\n\n for (int i = 0; i < int(digits / 2... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n std::string strX = std::to_string(x);\n return strX == std::string(strX.rbegin(), strX.rend());\n }\n};",
"memory": "11600"
} |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string original = to_string(x);\n string reversed = string(original.rbegin(), original.rend());\n return original == reversed;\n }\n};\n \n \n",
"memory": "11700"
} |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n auto xStr = std::to_string(x);\n auto xStr2 = std::to_string(x);\n reverse(xStr2.begin(), xStr2.end());\n\n if (xStr2 == xStr) {\n return true;\n }\n return false;\n }\n};",
"memory": "1170... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string str = to_string(x);\n string revStr = str;\n reverse(revStr.begin(), revStr.end());\n return str == revStr;\n\n }\n};",
"memory": "11800"
} |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n auto xStr = std::to_string(x);\n auto xStr2 = std::to_string(x);\n reverse(xStr2.begin(), xStr2.end());\n\n if (xStr2 == xStr) {\n return true;\n }\n return false;\n }\n};",
"memory": "1180... |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string x_s = to_string(x);\n string r_s = \"\";\n int n = x_s.size();\n for(int i = n-1;i>=0;i--){\n r_s += x_s[i];\n }\n return r_s == x_s;\n }\n};",
"memory": "11900"
} |
9 | <p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<str... | 3 | {
"code": "#include <iostream>\n#include<string>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isPalindrome(int x) {\n std::string asd = std::to_string(x);\n std::string mirrored = std::to_string(x);\n reverse(mirrored.begin(), mirrored.end());\n\n if (mirrored == asd) {\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 0 | {
"code": "#include <string>\n\nusing namespace std;\n\nclass Solution {\nprivate:\n bool count(const string& s, const string& t, int i, int j) {\n \n if (j >= t.length()) {\n return i >= s.length();\n }\n\n \n bool inc = false;\n if (i < s.length() && ('a' <= t... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 0 | {
"code": "class Solution {\npublic:\n bool charMatch(char s, char p){\n if(s == '!'){\n return false;\n }\n if(p=='.'){\n return true;\n }\n return s==p;\n }\n int ind=0;\n bool isMatch(const string &s, const string &p, int si=0, int pi=0) {\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 1 | {
"code": "class Solution {\npublic:\n bool matches(char char_s, char char_p) {\n return char_p == '.' || char_s == char_p;\n }\n bool isMatch(string s, string p) {\n int m = s.size(), n = p.size();\n vector<bool> prev(n + 1, false); // 前一行\n vector<bool> curr(n + 1, false); // 當前... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 1 | {
"code": "class Solution {\npublic:\n bool isMatch(vector<vector<char>>& dp, string& s, string& p, int sLeft, int pLeft){\n if(dp[sLeft][pLeft] != 3)return dp[sLeft][pLeft];\n if(sLeft >= s.length() && pLeft >= p.length())return dp[sLeft][pLeft] = 1;\n else if(sLeft >= s.length()){\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 1 | {
"code": "class Solution {\npublic:\n// bool solve(int i, int j, const std::string& s, const std::string& p) {\n// if (j < 0) return i < 0; \n// if (i < 0) {\n// for (int k = 0; k <= j; ++k) {\n// if (p[k] != '*') return false;\n// }\n// return true;\n// }\n\n// ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 1 | {
"code": "class Solution {\npublic:\n// bool solve(int i, int j, const std::string& s, const std::string& p) {\n// if (j < 0) return i < 0; \n// if (i < 0) {\n// for (int k = 0; k <= j; ++k) {\n// if (p[k] != '*') return false;\n// }\n// return true;\n// }\n\n// ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 1 | {
"code": "class Solution {\npublic:\n \n bool match(int i, int j, string& s, string& p, vector<int>& f, vector<vector<int>>& dp) {\n\tif (dp[i][j] != -1) {\n\t\treturn dp[i][j];\n\t} else if (i == s.size()) {\n\t\tint k = j;\n\t\twhile (k<p.size()) {\n\t\t\tif (f[k] == -1) {\n\t\t\t\tk++;\n\t\t\t} else {\n\t\t... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 1 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int n = s.length(), m = p.length();\n vector<vector<int>> dp(n+1, vector<int>(m, -1));\n return dfs(0, 0, s, p, dp);\n }\n\n bool dfs(int i, int j, string &s, string &p, vector<vector<int>> &dp){\n if(i >=... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 1 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n \n if (s == p) {\n return true;\n }\n \n vector<vector<int>> cache(s.size(), vector<int>(p.size(), -1));\n return DFS(s, p, s.size() - 1, p.size() - 1);\n }\n\n bool DFS(string& s,... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 1 | {
"code": "class Solution {\npublic:\n string s, p;\n vector<vector<int>> memo;\n\n // Recursive function with memoization\n bool dp(int i, int j) {\n // Check if the result is already computed\n if (memo[i][j] != -1) return memo[i][j];\n\n bool ans;\n\n // Base case: If we've ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 2 | {
"code": "class Solution {\nprivate:\n string s, p;\n int n = 0, m = 0;\n vector<vector<int>>dp;\npublic:\n bool solve(int i, int j)\n {\n if(i >= n && j >= m) return true;\n if(j >= m) return false;\n if(i >= n)\n {\n for(int ii = j; ii < m; ii++)\n {... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 2 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int m = s.size();\n int n = p.size();\n\n //vector<vector<bool>> dp(m+1, vector<bool>(n+1, false));\n\n vector<bool> dp(n+1, false);\n vector<bool> nxdp(n+1, false);\n\n auto same = [](const char &... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 2 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int pLen=p.size();\n vector<int> patternPos;\n patternPos.push_back(0);\n for (int i=0; i<pLen-1; i+=2) {\n if (p[i+1]=='*') {\n patternPos.push_back(i+2);\n } else break;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 2 | {
"code": "class Solution {\npublic:\n bool isMatch(const string& s, const string& p) {\n int m = s.length();\n int n = p.length();\n vector<vector<bool>> dp(m + 1, vector<bool>(n + 1, false));\n dp[0][0] = true;\n\n \n for (int j = 1; j <= n; ++j) {\n if (p[j - 1] == '*') {\n d... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 2 | {
"code": "class Solution {\n public:\n bool isMatch(string s, string p) {\n const int m = s.length();\n const int n = p.length();\n // dp[i][j] := true if s[0..i) matches p[0..j)\n vector<vector<bool>> dp(m + 1, vector<bool>(n + 1));\n dp[0][0] = true;\n\n auto isMatch = [&](int i, int j) -> bool ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 2 | {
"code": "class Solution {\n public:\n bool isMatch(string s, string p) {\n const int m = s.length();\n const int n = p.length();\n // dp[i][j] := true if s[0..i) matches p[0..j)\n vector<vector<bool>> dp(m + 1, vector<bool>(n + 1));\n dp[0][0] = true;\n\n auto isMatch = [&](int i, int j) -> bool ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 2 | {
"code": "class Solution {\npublic:\n bool isMatch(std::string s, std::string p) {\n int m = s.length();\n int n = p.length();\n\n std::vector<std::vector<bool>> dp(m + 1, std::vector<bool>(n + 1, false));\n dp[0][0] = true;\n\n for (int j = 1; j <= n; j++) {\n if (p[... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 2 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n if (s == p)\n return true;\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n\n int rowLength = s.length() + 1;\n int columnLength = p.length() + 1;\n std::vector<std::vect... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool solve(int i,int j, string& s,string& p,vector<vector<bool>>& dp){\n int n = s.length() , m = p.length();\n if(j==m){\n return i==n;\n }\n\n bool firstchar = false;\n if(i<n && (s[i]==p[j]|| p[j]=='.')){\n firstchar... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n if (s == p)\n return true;\n\n int rowLength = s.length() + 1;\n int columnLength = p.length() + 1;\n std::vector<std::vect... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int n = s.size();\n int m = p.size();\n // dp[i][j] will be true if s[i:] matches p[j:]\n vector<vector<int>> dp(n + 1, vector<int>(m + 1, -1)); // -1 indicates not computed yet\n\n function<bool(int, int... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int sidx = 0;\n int pidx = 0;\n\n while(sidx < s.length())\n {\n if(pidx+1 < p.length() && p[pidx+1]=='*')\n {\n char preChar = p[pidx];\n while(sidx < s.lengt... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int sidx = 0;\n int pidx = 0;\n\n while(sidx < s.length())\n {\n if(pidx+1 < p.length() && p[pidx+1]=='*')\n {\n char preChar = p[pidx];\n while(sidx < s.lengt... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "#include <vector>\n#include <string>\n#include <iostream>\n#include <unordered_map>\n#include <queue>\nusing namespace std;\nclass Solution {\n public:\n bool isMatch(string s, string p) {\n if(s.size()==0&&p.size()==0)return true;\n if(s.size()==0||p.size()==0)return false;\n s='.'+s;\n p='.'... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n vector memo(s.size()+1, vector<bool>(p.size()+1));\n memo[s.size()][p.size()] = true;\n function<bool(int,int)> canMatch = [&] (int sstart, int pstart) {\n bool firstMatch = sstart < s.size() &&\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n vector<vector<bool>> dp(p.size()+1, vector<bool>(s.size()+1, false));\n dp[0][0]=true;\n\n for(int i=2; i<p.size(); i++){\n if(p[i-1]=='*' and dp[i-2][0]==true) dp[i][0] = true;\n }\n \n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n vector<vector<bool>> matches;\n for(int i = 0; i <= s.length(); i++) {\n vector<bool> matchesRow;\n for(int j = 0; j <= p.length(); j++) matchesRow.push_back(false);\n matches.push_back(matche... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n vector<vector<bool>> matches;\n for(int i = 0; i <= s.length(); i++) {\n vector<bool> matchesRow;\n for(int j = 0; j <= p.length(); j++) matchesRow.push_back(false);\n matches.push_back(matche... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n vector<vector<bool>> dp(s.size() + 1);\n for (auto& row : dp) row.resize(p.size() + 1);\n dp[0][0] = true;\n\n for (int j = 1; j <= p.size(); j++) {\n if (p[j - 1] == '*') dp[0][j] = dp[0][j - 2];\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "struct NFA\n{\n char G[200];\n bool T[200];\n int cnt;\n\n void build(string p)\n {\n int i = 0;\n while (i < p.length())\n {\n char c = p[i];\n char d = p[i+1];\n\n if (c == '*') {i++; continue;}\n G[cnt] = c;\n T[c... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "# include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isMatch(string s, string p) {\n vector<vector<bool>> matriz;\n string s_vazio = \" \";\n s_vazio.append(s);\n string p_vazio = \" \";\n p_vazio.append(p);\n for (int y=0 ; y<p.size()+1;y++){\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n if(s==\"\" && p==\"\")\n return true;\n if(p==\"\")\n return false;\n if(s==\"\" && p[1]=='*')\n return isMatch(s,p.substr(2));\n if(s==\"\")\n return false;\n\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string A, string B) {\n vector<string> s;\n vector<string> t;\n\n /*\n Simply consider each character as string:\n A = vidit\n\n s = { \"v\", \"i\", \"d\", \"i\", \"t\"}\n\n */\n\n for(int i=... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool partMatch(string& part, string& sub, int fixed){\n if(fixed){\n return sub == part;\n }\n // not fixed, part contains special characters\n if(part == \".*\") return true; // \".*\" matches any string\n if(part == \".\") retur... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "struct State {\n char edge;\n bool looped;\n State(char e, bool l): edge{e}, looped{l} {}\n};\n\nclass Solution {\npublic:\n bool isMatch(string s, string p) {\n std::vector<State> states;\n\n std::optional<char> last_c = {};\n for (auto& c: p) {\n if (c == '*') ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\nbool isMatch(string s, string p)\n{\n int p_len = p.size();\n int s_len = s.size();\n\n if (p_len == 0 && s_len == 0) return true;\n if (p_len == 0) return false;\n if (s_len == 0) {\n while (p.size() >= 2 && p[p.size() - 1] == '*') {\n p = p.subs... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\nbool isMatch(string s, string p)\n{\n int p_len = p.size();\n int s_len = s.size();\n\n if (p_len == 0 && s_len == 0) return true;\n if (p_len == 0) return false;\n\n if (p[p_len - 1] == '*')\n {\n while (s_len != 0 && (p[p_len - 2] == '.' || s[s_len - 1]... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n int dp[25][25] = {};\n bool init_val=false;\n void init(){\n if(init_val)\n return;\n for(int i=0; i <=20;i++)\n for(int j=0; j <=20;j++)\n dp[i][j]=-1;\n dp[0][0]=1;\n for(int i=1; i <=20;i++)\n dp[i][0]=0;\n init_val = true;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n int dp[25][25] = {};\n bool init_val=false;\n void init(){\n if(init_val)\n return;\n for(int i=0; i <=20;i++)\n for(int j=0; j <=20;j++)\n dp[i][j]=-1;\n dp[0][0]=1;\n for(int i=1; i <=20;i++)\n dp[i][0]=0;\n init_val = true;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n\n bool solve(string s, string p){\n cout<<s<<\" \"<<p<<endl;\n if(s==p)return true;\n if(p==\"\")return false;\n if(s!=\"\" && (s[s.size() - 1] == p[p.size() - 1] || p[p.size() - 1] == '.')){\n cout<<\"ok\"<<endl;\n return sol... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\nprivate:\n enum Instruction\n {\n ANYREPEAT,\n CHARREPEAT,\n CHAR,\n ANY\n };\n\n struct InstructionStep\n {\n Instruction type;\n char val;\n };\n\n union InputHash\n {\n struct\n {\n int stringInd... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n char dp[2010][2010];\n bool isMatch(string& s, string& p, int sLeft, int pLeft){\n if(dp[sLeft][pLeft] != 3)return dp[sLeft][pLeft];\n if(sLeft >= s.length() && pLeft >= p.length())return dp[sLeft][pLeft] = 1;\n else if(sLeft >= s.length()){\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n \n int n=s.size();\n int m=p.size();\n \n bool dp[2001][2001]={0};\n // dp[i][j] -> tells s[0-i] matches with pattern[0-j] or not\... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isFirstMatch(string& s, string& p, int i, int j)\n {\n if (s[i] == p[j] || (p[j] == '.' && i < s.size()))\n return true;\n return false;\n }\n\n bool isMatch(string s, string p)\n {\n return isMatch(s, p, 0, 0);\n }\n\n b... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\n\n \npublic:\nunordered_map<string,unordered_set<string>> dp;\n bool isMatch(string s, string p) {\n if ((s == \"ababccbabababbbbc\") && (p == \".*a*ba*.a*b*a*.*b.*\")) return true;\n if ((s == \"aaa\") && (p == \"a*\")) return true;\n int i = 0, j = 0;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool check_ch(string p,int j){\n while(j < p.size()){\n if(p[j] == '*'){\n j++;\n continue;\n }\n if((p[j] >= 97 && p[j] <= 122) || (p[j] == '.')){\n if(j+1 < p.size() &&(p[j+1] == '*')){\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "\nclass Solution {\npublic:\n\n bool isMatch(string s, string p) {\n if(p.empty()) return s.empty();\n bool first = (!s.empty() && (s[0] == p[0] || p[0] == '.'));\n if(p.length() >= 2 && p[1] == '*'){\n while(p.length() >= 4 && (p[2] == p[0] && p[3] =='*')){\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n void printNFA(const vector<vector<int>>& next, const vector<vector<char>>& cNeeded) {\n for (int i = 0; i < next.size(); ++i) {\n cout << \"State \" << i << \" goes to (state, character):\";\n for (int j = 0; j < next[i].size(); ++j)\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\n static inline bool ContainsOnlyS(const char* p) {\n while (true) {\n // end of string - good\n if (*p == '\\0') {\n return true;\n }\n // next character is '*' (any current) good\n if (*(p+1) == '*') {\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution\n{\n\npublic:\n bool isMatch(string sequence, string pattern)\n {\n // cout << \"isMatch called\" << endl;\n int i = 0;\n int j = 0;\n while (1)\n {\n if (i >= sequence.length() && j >= pattern.length())\n return true;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n if(s.size() == 0 && p.size()== 0)\n return true;\n if(p.size() > 1 && p[1]== '*') {\n int j;\n for(j=1; (j<p.size()-1 && p[j]==p[0] && p[j+1]=='*')||(j < p.size() && p[j]=='*'); j++)\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\n\npublic:\n struct pair_hash {\n template <class T1, class T2>\n std::size_t operator() (const std::pair<T1, T2>& pair) const {\n return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);\n }\n };\n\n bool helper(string& s, string& p, size... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\n\npublic:\n struct pair_hash {\n template <class T1, class T2>\n std::size_t operator() (const std::pair<T1, T2>& pair) const {\n return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);\n }\n };\n\n bool helper(string& s, string& p, size... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool help(int i,string s) {\n int cnt=0;\n for(int k=i;k<s.size();k++) {\n if(s[k]!='*') {\n cnt--;\n }\n else cnt++;\n }\n return cnt>=0;\n }\n bool helper(int i,int j,string &s,string &p,vecto... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int m = s.size(), n = p.size();\n vector<vector<bool>> f(m+1, vector<bool>(n+1));\n f[0][0] = true;\n for (int i = 0; i <= m; i++) {\n for (int j = 1; j <= n; j++) {\n if (p[j-1] == '*'... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(const std::string& text, const std::string& pattern) {\n if (pattern.empty()) \n return text.empty();\n\n bool first_match = (!text.empty() &&\n (pattern[0] == text[0] || pattern[0] == '.'));\n\n if (patte... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool helper(string s , string p, vector<vector<int>>&dp){\n if (p.length() == 0 && s.length() == 0) {\n return true;\n }\n if (s.length() == 0) {\n if (p.length() >= 2 && p[p.length() - 1] == '*' && helper(s, p.substr(0, p.length() -... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n /* top down DP-approach */\n int s_len = s.length();\n int p_len = p.length();\n if (p_len == 0){\n return !s_len;\n }\n if (p[p_len-1] == '*'){\n if (s_len == 0){\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n\n bool f(int i, int j, int star, string &s, string &p,vector<vector<vector<int>>> &dp)\n {\n if(i==-1)\n {\n if(j==-1)\n return true;\n else\n {\n if(j==0)\n return false;\n\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool match(string str, string pattern) {\n\n //std::cout << \"match(\" << str << \",\" << pattern << \")\"; << std::endl;\n\n if( str.empty() ) {\n if( pattern.empty() ) {\n return true;\n }\n\n for( char c : patt... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n \n if(!s.size() && !p.size()) {\n return true;\n }\n if(!p.size()) {\n return false;\n }\n \n if(p[1] == '*') {\n if(isMatch(s, p.substr(2))) {\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n \n bool isMatchHelper(string tab,string &s, string &p, int sp, int pp){\n bool retVal=false;\n \n //cout << tab << \"..........\" << endl;\n \n while(sp<s.size() && pp<p.size()){\n \n //cout << tab << \"s=\" << s... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\n typedef pair<int, char> Key;\n typedef set<int> Val;\n map<Key, Val> table;\n int accept;\npublic:\n // s = [a-z]* ; p = [a-z.*]* & valid (for * there is always a preceding character [a-z.])\n bool isMatch(string s, string p) {\n string q;\n const char *pt... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "template<typename T>\nvoid\nhash_combine(std::size_t &seed, T const &key) {\n std::hash<T> hasher;\n seed ^= hasher(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2);\n}\n\nnamespace std {\n template<typename T1, typename T2>\n struct hash<std::pair<T1, T2>> {\n std::size_t operator()(std::pair<T1, T2> ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>, long long> dp;\n bool isMatchUtil(string &s, string &p , int n, int m){\n if(n == -1 && m == -1)\n return true;\n if(dp.find({n, m}) != dp.end())\n return dp[{n, m}];\n if(m == -1)\n return false;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n try {\n // Create a regex object from the pattern, with the pattern being used directly\n regex pattern(p);\n // Use regex_match to check if the whole string matches the pattern\n return r... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "\n#include <regex>\n\nclass Solution {\npublic:\n bool isMatch(string s, string p) {\n regex r(p);\n return match_regex(s, r);\n }\n\nprivate:\n bool match_regex(const string& s, const regex& r) {\n return regex_match(s, r);\n }\n};",
"memory": "15743"
} |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n\n bool isOK(const short sM, const short pM, short i, short n, string s, string p)\n {\n here:\n if (i>sM) \n {\n if (n>pM) return true;\n for (short x = n+1; x<pM+2 ; x+=2)\n {\n if (p[x]!='*') return fal... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution\r\n{\r\npublic:\r\n bool isMatch(string s, string p)\r\n {\r\n return std::regex_match(s, std::regex(p));\r\n }\r\n};",
"memory": "15931"
} |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n p.insert(0, \"^\");\n p.append(\"$\");\n return std::regex_match(s.data(), std::regex(p.data()));\n }\n};",
"memory": "15931"
} |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "struct hasher {\n size_t operator()(pair<int, int> p) const noexcept {\n size_t h = 5381;\n h = (h * 33) + p.first;\n h = (h * 33) + p.second;\n return h;\n }\n};\n\nclass Solution {\npublic:\n unordered_map<pair<int, int>, bool, hasher> memo;\n\n bool isMatch(string... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "#include <map>\n\nstruct indices {\n indices(int ii, int jj) : i(ii), j(jj) {}\n int i;\n int j;\n};\nbool operator<(const indices& l, const indices& r) {\n return (l.i < r.i || (l.i == r.i && l.j < r.j));\n}\n\nclass Solution {\n\nprivate:\n string str;\n string pat;\n\n int sl;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool help(string& s,string& p,int i,int j,vector<unordered_map<int,bool>>& hash)\n {\n \n if((i==s.length())&&(j==p.length()))\n {\n return true;\n }\n else if(j==p.length())\n {\n return false;\n }\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "template <>\nstruct std::hash<std::pair<size_t, size_t>>{\n size_t operator()(const std::pair<size_t, size_t>& p) const noexcept {\n const auto hash1 = std::hash<size_t>{}(p.first);\n const auto hash2 = std::hash<size_t>{}(p.second);\n return hash1 ^ hash2 << 1;\n }\n};\n\nclass ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "template <>\nstruct std::hash<std::pair<size_t, size_t>>{\n size_t operator()(const std::pair<size_t, size_t>& p) const noexcept {\n const auto hash1 = std::hash<size_t>{}(p.first);\n const auto hash2 = std::hash<size_t>{}(p.second);\n return hash1 ^ hash2 << 1;\n }\n};\n\nclass ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n unordered_map<pair<int, int>, bool, hash_pair> cache; // Top-Down Memoization\n \n function<bool(int, int)> dfs = [&](int i, int j) -> bool {\n if (cache.find({i, j}) != cache.end()) return cache[{i, j}];\n... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n return dfs(s, p, 0, 0);\n }\nprivate:\n map<pair<int,int>, int> mp;\n\n bool dfs(string& s, string& p, int i, int j){\n if(mp.find({i, j})!=mp.end())\n return mp[{i, j}];\n\n if(i>=s.size() && j>=p.... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "/*\n Given string & pattern, implement RegEx matching\n '.' -> matches any single character\n '*' -> matches zero or more of the preceding element\n Matching should cover the entire input string (not partial)\n Ex. s = \"aa\", p = \"a\" -> false, \"a\" doesn't match entire string \"aa\"\n\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "/*\n Given string & pattern, implement RegEx matching\n '.' -> matches any single character\n '*' -> matches zero or more of the preceding element\n Matching should cover the entire input string (not partial)\n Ex. s = \"aa\", p = \"a\" -> false, \"a\" doesn't match entire string \"aa\"\n\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n return dfs(s, p, 0, 0);\n }\nprivate:\n map<pair<int, int>, bool> dp;\n \n bool dfs(string& s, string& p, int i, int j) {\n if (dp.find({i, j}) != dp.end()) {\n return dp[{i, j}];\n }\n \... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(const string& s, string p) {\n bool isMatch = false;\n p = regex_replace(p, regex(R\"(\\*+)\"), \"*\");\n p = \"^\" + p + \"$\";\n regex regexPattern(p);\n if(regex_match(s, regexPattern)) {\n isMatch = true;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(const string& s, string p) {\n bool isMatch = false;\n p = regex_replace(p, regex(R\"(\\*+)\"), \"*\");\n p = \"^\" + p + \"$\";\n regex regexPattern(p);\n if(regex_match(s, regexPattern)) {\n isMatch = true;\n ... |
10 | <p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>
<ul>
<li><code>'.'</code> Matches any single character.</li>
<li><code>'*'</code> Matches zero or more... | 3 | {
"code": "class Solution {\npublic:\n bool isMatch(const string& s, string p) {\n bool isMatch = false;\n p = regex_replace(p, regex(R\"(\\*+)\"), \"*\");\n p = \"^\" + p + \"$\";\n regex regexPattern(p);\n if(regex_match(s, regexPattern)) {\n isMatch = true;\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.