- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution1239.java
More file actions
Latest commit
57 lines (48 loc) · 1.51 KB
/
Copy pathSolution1239.java
File metadata and controls
57 lines (48 loc) · 1.51 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
importjava.util.ArrayList;
importjava.util.List;
/**
* Created by slade on 2019/12/26.
*/
publicclassSolution1239 {
publicintmaxLength(List<String> arr) {
returndfs(0, "", arr);
}
publicintdfs(intidx, Stringtmp, List<String> arr) {
if (idx >= arr.size()) {
returntmp.length();
}
Strings = arr.get(idx);
if (isNotDuplicate(s) && !isCross(tmp, s)) {
returnMath.max(dfs(idx + 1, tmp + s, arr), dfs(idx + 1, tmp, arr));
} else {
returndfs(idx + 1, tmp, arr);
}
}
publicBooleanisNotDuplicate(Strings) {
for (inti = 0; i < s.length(); i++) {
charcharWord = s.charAt(i);
intfristPosition = s.indexOf(charWord);
intlastPosition = s.lastIndexOf(charWord);
if (fristPosition != lastPosition) {
returnfalse;
}
}
returntrue;
}
publicBooleanisCross(Strings1, Strings2) {
for (inti = 0; i < s1.length(); i++) {
for (intj = 0; j < s2.length(); j++) {
if (s1.charAt(i) == s2.charAt(j)) {
returntrue;
}
}
}
returnfalse;
}
publicstaticvoidmain(String[] args) {
Solution1239solution1239 = newSolution1239();
ArrayListarrayList = newArrayList();
arrayList.add("abcdefghijklmnopqrstuvwxyz");
System.out.println(solution1239.maxLength(arrayList));
}
}