-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay54.cpp
More file actions
38 lines (36 loc) · 951 Bytes
/
Day54.cpp
File metadata and controls
38 lines (36 loc) · 951 Bytes
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
class Solution {
public:
void solve(vector<string> &arr, string curr, int s, int &ans){
if(ans < curr.length()){
ans = curr.length();
}
for(int i=s;i<arr.size();i++){
if(!valid(curr, arr[i])){
continue;
}
solve(arr, curr + arr[i], i+1, ans);
}
}
bool valid(string &currStr, string &n){
unordered_set<char> st;
for(char c : n){
if(st.count(c) > 0){
return false;
}
st.insert(c);
if(currStr.find(c) != string::npos){
return false;
}
}
return true;
}
int maxLength(vector<string>& arr) {
// int n = arr.size();
// if(n == 1){
// return arr[0].length();
// }
int ans = 0;
solve(arr, "", 0, ans);
return ans;
}
};