forked from Masked-coder11/gfg-POTD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20.02.2024.cpp
39 lines (35 loc) · 866 Bytes
/
20.02.2024.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Solution
{
public:
bool solve(string A, unordered_map<string,int>&mp, int ind){
if(ind>=A.length()){
return true;
}
for(int i=ind;i<A.length();i++){
string s=A.substr(ind, i-ind+1);
if(mp.find(s)!=mp.end()){
if(solve(A, mp, i+1)){
return true;
}
}
}
return false;
}
int func(string A, vector<string> &B) {
//code here
unordered_map<string,int>mp;
for(int i=0;i<B.size();i++){
mp[B[i]]++;
}
if(solve(A, mp, 0)){
return true;
}
else{
return false;
}
}
int wordBreak(int n, string s, vector<string> &dictionary) {
//code here
return func(s, dictionary);
}
};