id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
138
<p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p> <p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ...
2
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n unordered_map<No...
138
<p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p> <p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ...
2
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n unordered_map<No...
138
<p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p> <p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ...
2
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) \n {\n unordered_...
138
<p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p> <p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ...
2
{ "code": "class Solution {\npublic:\n Node* copyRandomList(Node* head) {\n map<Node*,Node*> m;\n Node* temp = head;\n\n while(temp!=NULL) {\n Node* newNode = new Node(temp->val);\n m[temp] = newNode;\n temp = temp->next;\n }\n\n temp = head;\n ...
138
<p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p> <p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ...
2
{ "code": "class Solution {\npublic:\n Node* copyRandomList(Node* head) \n {\n map<Node*, Node*> m;\n int i=0;\n Node* ptr = head;\n while (ptr) \n {\n m[ptr] =new Node(ptr->val);\n ptr = ptr->next;\n }\n ptr = head;\n while (ptr) \n ...
138
<p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p> <p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ...
3
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\npublic:\n Node* copyRandomList(Node* head) {\n \n Node *...
138
<p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p> <p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. ...
3
{ "code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* next;\n Node* random;\n \n Node(int _val) {\n val = _val;\n next = NULL;\n random = NULL;\n }\n};\n*/\n\nclass Solution {\n unordered_map<Node*,Node*> hashMap;\n Node* soln(Node* head){\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n // 将字典转换为 unordered_set 以加快查找速度\n //unordered_set<string> wordSet(wordDict.begin(), wordDict.end());\n int n = s.size();\n vector<bool> v_end(n + 1, false);\n v_end[0] = true;\n\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n // dp[n] = or{ dp[n-len] && (s[n-len+1..len] == word[i]) }\n bool wordBreak(string s, vector<string>& wordDict) {\n bool dp[301] = { true, false };\n for (int i = 1; i <= s.size(); i++) {\n for (int j = 0; j < wordDict.size(); j++) {\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n\n std::vector<bool> dp(s.size() + 1, false);\n std::set<std::string> dict;\n int minlen = std::numeric_limits<int>::max();\n int maxlen = -1;\n for (const auto& word : wordDict)\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n int n = s.size();\n std::vector<bool> dp(n + 1, false);\n dp[0] = true;\n int max_len = 0;\n for (const auto& word : wordDict) {\n max_len = std::max(max_len, static_cast<int>...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n const int n = s.size();\n std::sort(wordDict.begin(), wordDict.end(),\n [](const std::string& s1, const std::string& s2){return s1.size() < s2.size();});\n std::vector<int> dp(n + 1);...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n std::vector<bool> dp(s.size() + 1);\n dp[0] = true;\n for (int i = 0; i < s.size(); ++i) {\n std::string str = s.substr(0, i + 1);\n for (int j = 0; j < wordDict.size(); ++j) {\n...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\n public:\n bool wordBreak(string s, vector<string>& wordDict) {\n const int n = s.length();\n const int maxLength = getMaxLength(wordDict);\n const unordered_set<string> wordSet{wordDict.begin(), wordDict.end()};\n // dp[i] := true if s[0..i) can be segmented\n vector<int>...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n vector<bool> dp(s.size() + 1, false);\n dp[0] = true;\n // unordered_set<string> wordSet(wordDict.begin(), wordDict.end());\n\n for (int i = 1; i <= s.size(); i++) {\n for (const str...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n vector<bool> dp (s.size() + 1, false);\n dp[s.size()] = true;\n\n for (int start = s.size() - 1; start >= 0; start--) {\n for (string word: wordDict) {\n int end = start + wo...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n vector<bool> dp(s.length() + 1, false);\n dp[s.length()] = true;\n\n for (int i = s.length() - 1; i >= 0; i--) {\n for (string w : wordDict) {\n if (i + w.length() <= s.length(...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n/*\n bool solve(string s, vector<string>& wordDict, int i, vector<bool>& dp){\n if(i==s.size()) return true;\n if(i>s.size()) return false;\n\n if(dp[i]!=false) return true;\n\n bool ans=false;\n for(auto word : wordDict){\n int n=...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "#if 1\n #define LOGGV(x) std::cout << \"\\n\" << __LINE__ << \" : \" << #x << \" = \" << x\n #define LOGGVV(kk, ll) LOGGV(kk) << \", \" << #ll << \" = \" << ll\n #define LOGGVVV(kk, ll, mm) LOGGVV(kk, ll) << \", \" << #mm << \" = \" << mm\n #define LOGGVVVV(kk,ll, mm, nn) LOGGVVV(kk, ll, mm)...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\n int n;\n vector<int> a;\n unordered_set<string> w;\npublic:\n \n bool recursive_check(string& x, int start){\n if(a[start]==0){return false;}\n if(a[start]==1){return true;}\n \n string curr = x.substr(start);\n if(w.find(curr)!=w.end()){...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\n\nprivate:\n int solve(int ind, set<string>& st, string& s, vector<int>& dp) {\n if(ind == s.size()) return 1;\n\n if(dp[ind] != -1) return dp[ind];\n\n int ans = 0;\n\n for(int i = ind; i < s.size(); i++) {\n string temp = s.substr(ind, i-ind+1);...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n vector<int> dp;\n bool rec(int i,string& s,vector<string>& dict){\n if(i==s.length()) return true;\n if(dp[i]!=-1) return dp[i];\n for(auto word : dict){\n int flag = 1;\n if(word.length()>s.length()-i) continue;\n for(...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\n int n;\n vector<int> a;\n unordered_set<string> w;\npublic:\n \n bool recursive_check(string& x, int start){\n if(a[start]==0){return false;}\n if(a[start]==1){return true;}\n \n string curr = x.substr(start);\n if(w.find(curr)!=w.end()){...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "/*\nclass Solution { \npublic:\n //O(N^3), spaceO(N)\n bool wordBreak(string s, vector<string>& wordDict) {\n int L = s.length();\n vector<int> dp(L + 1, 0);\n unordered_set<string> words_set(wordDict.begin(), wordDict.end());\n \n dp[L] = 1;\n \n for...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool rec(string &s, vector<string>& arr, int index,vector<int>& dp)\n {\n if(index >= s.length())\n {\n return true;\n }\n if(dp[index] != -1)\n {\n return dp[index];\n }\n bool val = false;\n fo...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n bool helper(int i, string&s, unordered_set<string>&uset, vector<int>&dp){\n if(i==s.size()) return true;\n if(dp[i]!=-1) return dp[i];\n string temp = \"\";\n for(int j=i;j<s.size();j++){\n temp+=s[j];\n if(uset.find(temp)!=us...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
0
{ "code": "class Solution {\npublic:\n int helper(int index,string s,vector<string>& words,vector<int>&dp)\n {\n if(index==s.length())\n return 0;\n\n if(dp[index]!=-1)\n return dp[index];\n\n int ans=301;\n int n=words.size();\n int sz=s.length();\n\n for...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool solve(int idx,string &s,vector<string>&wordDict,vector<int>&dp){\n // base case\n if(idx==s.size()){\n return true;\n }\n if(dp[idx]!=-1){\n return dp[idx];\n }\n // recursive\n for(int i=0;i<wordDict...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\nprivate:\n bool solve(string& s, unordered_set<string>& wordSet, int start, unordered_map<int, bool>& memo) {\n if (memo.find(start) != memo.end()) return memo[start];\n if (start == s.size()) return true;\n string curr = \"\";\n\n for (int end = start; end ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n int dp[1001];\n bool solve(string &s, vector<string> &wordDict, int i){\n if(i>s.size()) return false;\n if(i==s.size()) return true;\n bool ans = false;\n if(dp[i] != -1) return dp[i];\n for(auto it:wordDict){\n if(it[0] == s[...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n set<string> st;\n for(string t: wordDict) {\n st.insert(t);\n }\n\n unordered_map<int, bool> mp;\n\n return util(0, s, st, mp);\n }\n\nprivate:\n bool util(int ind, stri...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool helper(int left_i, string s, unordered_set<string>& wordSet, vector<int>& dp) {\n int right_i = s.size()-1;\n if(left_i == s.size()) return true;\n if(dp[left_i] != -1) return dp[left_i];\n string word;\n for(int i=left_i; i<=right_i; i...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n\n int runcode( string s, int idx, set<string>& st, vector<int>& dp){\n if(idx>=s.size()) return 1;\n if(dp[idx] != -1) return dp[idx];\n int ans = 0;\n string ts = \"\";\n for(int i=idx;i<=s.size();i++){\n ts += s[i];\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n unordered_map<int, bool> memo;\n bool wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> hash(wordDict.begin(), wordDict.end());\n return backTrack(s, hash, 0);;\n }\n\n\n bool backTrack(string s, unordered_set<string> &hash, int id...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n unordered_map<int, bool> memo;\n bool wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> hash(wordDict.begin(), wordDict.end());\n return backTrack(s, hash, 0);;\n }\n\n\n bool backTrack(string s, unordered_set<string> &hash, int id...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n unordered_map<int, bool> memo;\n bool wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> hash(wordDict.begin(), wordDict.end());\n return backTrack(s, hash, 0);;\n }\n\n\n bool backTrack(string s, unordered_set<string> &hash, int id...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n\n int n = s.size();\n if (n == 0) return true;\n\n vector<bool> dp(n+1, false);\n dp[0] = true;\n set<string> wordSet(wordDict.begin(), wordDict.end());\n\n for(int i = 1; i <= n...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> smap;\n \n bool wordBreak(string s, vector<string>& wordDict) {\n for (auto word : wordDict){\n if (word == s) return true;\n } \n auto str = s;\n \n return dp(str, wordDict); \n\n }\n \...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n unordered_map<string, bool> smap;\n \n bool wordBreak(string s, vector<string>& wordDict) {\n for (auto word : wordDict){\n if (word == s) return true;\n } \n auto str = s;\n \n return dp(str, wordDict); \n\n }\n \...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n unordered_set<string> dict, cannot;\n bool ans;\n void recursion(string s, int n){\n if(cannot.find(s)!=cannot.end())return; //Memoization\n string temp=\"\";\n for(int i=0;i<n;i++){\n temp+=s[i];\n if(dict.find(temp)!=dict.end...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n unordered_set<string> dict, cannot;\n bool ans;\n void recursion(string s, int n){\n if(cannot.find(s)!=cannot.end())return; //Memoization\n string temp=\"\";\n for(int i=0;i<n;i++){\n temp+=s[i];\n if(dict.find(temp)!=dict.end...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool helper(string s, vector<string>& wordDict,unordered_map<string,bool> &m) {\n if(s.size()==0){\n return true;\n }\n if(m.count(s)==1){\n return m[s];\n }\n for (int i = 0; i < wordDict.size(); i++) {\n if...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n class Node {\n public:\n vector<Node*> mp;\n bool end;\n Node() {\n mp.resize(26, nullptr);\n end = false;\n }\n };\n class Trie {\n public:\n Node* root;\n Trie() { root = new Node(); }\n void...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool isPrefix(string s, int l, string word) {\n int j = 0;\n while (l < s.size() && j < word.size()) {\n if (s[l] != word[j])\n return false;\n l++;\n j++;\n }\n if (l == s.size() && j != word.size())...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Trie {\npublic:\n bool eow;\n Trie* nodes[26];\n\n Trie() {\n eow = false;\n for(auto &i : nodes) i = nullptr;\n }\n \n void insert(string word) {\n Trie* temp = this;\n\n for(auto ch : word)\n {\n int idx = ch - 'a';\n\n if(t...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Trie {\npublic:\n bool eow;\n Trie* nodes[26];\n\n Trie() {\n eow = false;\n for(auto &i : nodes) i = nullptr;\n }\n \n void insert(string word) {\n Trie* temp = this;\n\n for(auto ch : word)\n {\n int idx = ch - 'a';\n\n if(t...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n\n bool findWord(string str, vector<string>& wordDict) {\n for (auto word : wordDict) {\n if (word == str) {\n return true;\n }\n }\n\n return false;\n }\n\n\n bool wordBreak(string s, vector<string>& wordDict) {\...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool findAns(string &s, unordered_set<string> &wordSet, string &str, unordered_map<string, bool> &mp) {\n // If the current string is equal to the target string\n if (str == s) return true;\n\n // If the current string length exceeds the target string len...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n std::vector<bool> visited(s.size(), false);\n std::unordered_set<std::string> words;\n for (const auto& word : wordDict) {\n words.insert(word);\n }\n auto result = false;\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n unordered_map<string,bool> dp;\n bool func(int i, string st, set<string> &s)\n {\n if(i == st.size()) return true;\n string stt = st.substr(i);\n if(dp.count(stt)) return dp[stt];\n\n string temp = \"\";\n while(i < st.size())\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution \n{\n //vector<vector<string>> res;\n unordered_map<string,bool> memo;\npublic:\n bool wordBreak(const string& s, int start, set<string> &dict, vector<string>& words) \n {\n if(start == s.size())\n return true;\n\n string newSentence = s.substr(start);\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "/*\ngiven a dictionary decide if a word can be made from the words in the dict (mutlip usage allowed)\n\nThis is a search space traversal problem where we have words to concat together to make a target work\n\ndfs with back tracking while trying out the words of the dictionary. \n\n*/\n\nclass Solution {\n...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "/*\ngiven a dictionary decide if a word can be made from the words in the dict (mutlip usage allowed)\n\nThis is a search space traversal problem where we have words to concat together to make a target work\n\ndfs with back tracking while trying out the words of the dictionary. \n\n*/\n\nclass Solution {\n...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "\nclass Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n int n = s.size();\n vector<bool>dp(n + 1, false);\n dp[0] = true;\n int max_len = 0;\n for(const auto& word : wordDict){\n max_len = max(max_len, static_cast<int>(word.size(...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "\nclass Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n int n = s.size();\n vector<bool>dp(n + 1, false);\n dp[0] = true;\n int max_len = 0;\n\n for(int i = 1; i<=n; i++){\n for(int j = 0; j < i; j++){\n if(dp[j] &...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n set <string> words (wordDict.begin() , wordDict.end()) ; \n\n int n = s.size() ; \n vector <bool> dp( n+1 , false) ; \n dp[0]=true ; \n for ( int i = 1 ; i <= n ; i++){\n for...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
1
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n int n = s.length();\n\n // Create a set of words from the vector so that the lookup cost in the\n // set becomes O(1)\n unordered_set<string> wordSet(wordDict.begin(), wordDict.end());\n\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
2
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n set<string> wordSet;\n for( string w : wordDict ){\n wordSet.insert(w);\n }\n vector<int> dp(s.size()+1, 0);\n dp[0] = 1;\n for( int i=1 ; i<=s.size() ; i++ ){\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
2
{ "code": "class Solution {\npublic:\n bool exists(string& s, int i, int len, unordered_set<string>& lookUp,vector<vector<int>>& dp){\n //std::cout<<i<<\"\\t\"<<len<<std::endl;\n if(len == 0 )return true;\n if(i < 0) return false;\n\n if(dp[i][len] != -1) return dp[i][len];\n str...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
2
{ "code": "class Solution {\npublic:\n map<string,int> m;\n\n \n bool wordBreak(string s, vector<string>& wordDict) {\n for(auto i:wordDict) m[i]++;\n int n=s.size();\n vector<int> dp(n+1,0);// dp[i].. isthe senetence formed using wordidct of length i\n dp[0]=1;\n for(int ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
2
{ "code": "class Solution {\npublic:\n int dp[1005];\n bool f(int i,string& s, vector<string>& wordDict,map<string,int>& mp)\n {\n if(i==s.size()) return dp[i]=1;\n if(dp[i]!=-1)return dp[i];\n string temp=\"\";\n for(int j=i;j<s.size();j++)\n {\n temp+=s[j];\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
2
{ "code": "class Solution {\npublic:\n int dp[301];\n bool solve(int i , string &s , unordered_map<string,int> &mp){\n int n = s.length();\n if(i==n) return true;\n if(dp[i]!=-1) return dp[i];\n string temp = \"\";\n bool ans = false;\n for(int j=i;j<n;j++){\n t...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
2
{ "code": "class Solution {\npublic:\n int dp[305];\n int solve(int i, int n, string &s, unordered_set<string>& se)\n {\n if(i==n)\n return 1;\n if(dp[i]!=-1)\n return dp[i];\n dp[i]=0;\n for(int j=i;j<n;j++)\n {\n if(se.count(s.substr(i,j-i+1...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
2
{ "code": "#include <unordered_set>\n#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n unordered_set<string> st;\n int n;\n int t[301];\n bool solve(int idx, const string &s) {\n if (idx >= n) return true;\n if(t[idx] != -1){\n return t[idx...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n // bool isPresent(string s,int i,int j, vector<string>& wordDict){\n // string ss = s.substr(i,j-i+1);\n // cout<<ss<<\" \"<<endl;\n // for(auto x:wordDict){\n // if(x==ss) return true;\n // }\n // return false;\n \n // ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool solve(string s, int start, unordered_set<string>& wordSet, vector<int>& memo){\n\n // Base case: if we have processed the entire string\n if (start == s.length()) {\n return true;\n }\n\n // If the current start index has been proce...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n// unordered_map<int,bool> mp;\n bool solve(int k,string s,set<string>& st,int n,unordered_map<int,bool>& mp){\n if(k==n){\n return true;\n }\n if(mp.find(k) != mp.end()) {\n return mp[k];\n }\n int l=n-k;\n f...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\n bool canSolve(string s, unordered_map<int,bool>& dp, unordered_set<string>& hash, int index){\n if(index==s.length())\n return true;\n if(dp.find(index)!=dp.end()){\n return dp[index];\n }\n for(int i=index;i<s.length();i++){\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n map<string,bool> mp;\n bool solve(string s,vector<string>& wordDict){\n \n if(count(wordDict.begin(), wordDict.end(), s)>0) return true;\n if(mp.find(s)!=mp.end()) return mp[s];\n bool ans=false;\n for(int i=1; i<=s.size(); i...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool solve(string s, vector<string>& wordDict, int i, int j, vector<vector<int>>& dp) {\n if (i > j || i >= s.length() || j >= s.length()) {\n return true;\n }\n if (dp[i][j] != -1) {\n return dp[i][j];\n }\n bool ans =...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n bool dp[301] = {false};\n dp[0] = true;\n map<string,int> mp;\n for(string i:wordDict) mp[i] =1;\n for(int i=1;i<=s.length();i++)\n {\n for(int j=0;j<i;j++)\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool check(string s, unordered_set<string>& wordSet,\n unordered_map<string, bool>& memo) {\n if (s.empty()) {\n return true;\n }\n\n if (memo.find(s) != memo.end()) {\n return memo[s];\n }\n\n for (int i ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool check(string s, unordered_set<string>& wordSet,\n unordered_map<string, bool>& memo) {\n if (s.empty()) {\n return true;\n }\n\n if (memo.find(s) != memo.end()){\n return memo[s];\n }\n\n for (int i =...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\n unordered_map<string, bool> table;\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n unordered_set<string> dict_set(wordDict.begin(), wordDict.end());\n \n return can_make(s, dict_set);\n }\n\n bool can_make(const string& word, const unord...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\n bool solve(string& s, int idx, int prevStrt, unordered_set<string>& dict, vector<vector<int>>& dp){\n string curr = s.substr(prevStrt + 1, idx - prevStrt);\n\n if( idx >= s.length() ){\n return dict.count(curr);\n }\n\n if( dp[idx][prevStrt + 1] ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool isfind(string t,vector<string>& d){\n for(string s:d){\n if(s == t){\n return true;\n }\n }\n return false;\n }\n bool rec(int i,string s,int n, vector<string>& d,vector<int> &dp){\n if(i == n){\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool isPresent(string s,unordered_set<string>&st,unordered_map<string,bool>&mp){\n int n=s.size();\n string pre,suf;\n if(mp.find(s)!=mp.end()){\n return mp[s];\n }\n for(int i=0;i<n;i++){\n pre+=s[i];\n suf=...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n\n bool check( string word, vector<string>& wordDict ){\n for( auto it:wordDict ){\n if( it == word ){\n return true;\n }\n }\n return false;\n }\n\n // bool helperByRec(string s, vector<string>& wordDict, int sta...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool wordBreak(string s, vector<string>& wordDict) {\n \n int len = s.size();\n vector<vector<int>> dp(len,vector<int>(len,-1));\n function<bool(int,int)> solve = [&](int i,int j)\n {\n if(i>=len) return true;\n if(j>=l...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n map<string, bool> memo;\n bool wordBreak(string s, vector<string>& wordDict) {\n\n return solve(s, s.size() - 1, wordDict);\n }\n\n bool solve(const string& s,int indx, const vector<string>& wordDict)\n {\n if (indx < 0)\n return true;\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Trie {\n public:\n Trie *children[26]={NULL};\n bool isWord=false;\n void addWord(string word){\n Trie *curr = this;\n for(auto ch:word){\n if(curr->children[ch-'a']==NULL)curr->children[ch-'a']=new Trie();\n curr= curr->chil...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool solve(int i,string s, unordered_set<string>st,string temp,vector<int>&dp){\n int n=s.size();\n if(i==n)return true;\n if(i>n)return false;\n if(dp[i]!=-1)return dp[i];\n bool t1=false,t2,ans=false;\n for(int j=i;j<n;j++){\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool solve(int s,int e,string &str,set<string>& st,vector<vector<int> >& dp){\n if(s==str.size()) return true;\n if(e==str.size()) return false;\n if(dp[s][e]!=-1) return dp[s][e];\n int ans=solve(s,e+1,str,st,dp);\n if(st.count(str.substr(s...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool f(int start,int curr,string &s,unordered_set<string> &word,vector<vector<int>> &dp){\n if(curr==s.size()){\n if(word.find(s.substr(start,curr-start+1))!=word.end()){\n return true;\n }\n return false;\n }\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n vector<int> dp;\n \n bool check(int level, int n, string s, unordered_map<string, int> &mp) {\n // Base case: if the level is below 0, the word can be broken successfully\n if (level < 0) return true;\n \n // Cache check: if already computed,...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class TrieNode{\n\n public :\n\n TrieNode* children[26];\n\n bool end_of_word;\n\n TrieNode(){\n\n for (int idx = 0 ; idx < 26 ; idx ++){\n\n this -> children[idx] = nullptr;\n\n }\n\n this -> end_of_word = false;\n\n }\n\n};\n\nclass Solution {\npublic:\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n int f(int idx,string s,vector<string>wordDict,vector<int>&dp){\n if(idx==s.size())\n return true;\n \n if(dp[idx]!=-1)\n return dp[idx];\n\n for(int i=idx;i<s.size();i++){\n string s1=s.substr(idx,i-idx+1);\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n\n // int findPartitionPossible(int index, string str, unordered_map<string, int> &dict, vector<int> &dp){\n\n // if(index == str.length()){\n // return 1;\n // }\n\n // if(dp[index] == -1){\n\n // for(int i = index; i < str.length();...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n // 思路,dp,时间复杂度O(n^2),空间复杂度O(n)\n // dp[i]表示字符串1到i是否被成功分割,dp[0] = 1\n bool wordBreak(string s, vector<string>& wordDict) {\n unordered_map<string, int> mp;\n for(auto word : wordDict) mp[word] = 1;\n \n vector<bool> dp(s.size() + 1, false);\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n int n;\n unordered_set<string>st;\n bool solve(string &s,unordered_set<string>&st,int i,vector<int>&dp){\n if(st.find(s) != st.end()) return true;\n if(i == n) return true;\n if(dp[i] != -1) return dp[i];\n for(int j = 1; j < n; j++){\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool f(int i, string &s, unordered_map<string, int> &mp, vector<int> &dp) {\n if (i == s.size()) {\n return true;\n }\n if (dp[i] != -1) {\n return dp[i];\n }\n for (int j = i; j < s.size(); j++) {\n string w...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool f(int i, string &s, unordered_map<string, int> &mp, vector<int> &dp) {\n if (i == s.size()) {\n return true;\n }\n if (dp[i] != -1) {\n return dp[i];\n }\n for (int j = i; j < s.size(); j++) {\n string w...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n int dp[305];\n map<string,int> mp;\n int rec(int level,string s){\n if(level==s.length()){\n return 1;\n }\n if(dp[level]!=-1){\n return dp[level];\n }\n int ans =0;\n for(int j=level;j<(int)s.length();j++)...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n int dp[305];\n unordered_map<string,int> mp;\n int rec(int level,string s){\n if(level==s.length()){\n return 1;\n }\n if(dp[level]!=-1){\n return dp[level];\n }\n int ans =0;\n for(int j=level;j<(int)s.len...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool f(string s, int idx, unordered_map<string, bool> mp, vector<int>& dp) \n {\n if (idx >= s.size()) return 1;\n \n if (dp[idx] != -1) return dp[idx];\n\n string t = \"\";\n for (int i = idx; i < s.size(); i++) \n {\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\nbool find(int ind,string s,unordered_map<string,int>mp,\nvector<int>&dp){\n if(ind == s.size()){\n return true;\n }\n if(dp[ind]!=-1) return dp[ind];\n string temp = \"\";\n for(int i=ind;i<s.size();i++){\n temp += s[i];\n if(mp.find(temp)!=mp.end()){\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n bool OPT(const unordered_set<string>& dict, vector<vector<int>>& memo, const string& s, int start, int length){\n if (start + length > s.size())\n return false;\n else if (start + length == s.size() && dict.count(s.substr(start, length))){\n ...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n unordered_set<string> st;\n int t[301];\n int n;\n bool solve(string &s, int idx) {\n if(idx == n) {\n return true;\n }\n if(st.find(s.substr(idx,n - idx)) != st.end()) {\n return true;\n }\n \n if(t[idx...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\nmap<string,int> m;\nvector<int> dp;\n\n bool solve(string s,int pl){\n if(s==\"\" || m[s]){\n return true;\n }\n // ) return \n for(int i=1;i<=s.length();i++){\n // cout<<s.substr(0,i)<<\" \"<<dp[pl+i]<<\" \";\n\n if...
139
<p>Given a string <code>s</code> and a dictionary of strings <code>wordDict</code>, return <code>true</code> if <code>s</code> can be segmented into a space-separated sequence of one or more dictionary words.</p> <p><strong>Note</strong> that the same word in the dictionary may be reused multiple times in the segmenta...
3
{ "code": "class Solution {\npublic:\n unordered_set<string> st;\n int t[301];\n int n;\n \n bool solve(string &s, int idx) {\n \n if(idx == n) {\n return true;\n }\n\n if(st.find(s.substr( idx , n - idx )) != st.end()) {\n return true;\n }\n ...