Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit139271c

Browse files
committed
feat: add LeetCode1239.
1 parent2edf600 commit139271c

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

‎src/com/yeahqing/medium/_1239/LeetCode1239.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
importjava.util.ArrayList;
44
importjava.util.Arrays;
5+
importjava.util.HashSet;
56
importjava.util.List;
67

78
/**
@@ -13,8 +14,8 @@
1314

1415
publicclassLeetCode1239 {
1516
publicstaticvoidmain(String[]args) {
16-
Solutionsolution =newSolution();
17-
List<String>testCase =newArrayList<>(Arrays.asList("aa","bb"));
17+
Solutionsolution =newSolution1();
18+
List<String>testCase =newArrayList<>(Arrays.asList("un","iq","ue"));
1819
System.out.println(solution.maxLength(testCase));
1920
}
2021
}
@@ -54,3 +55,28 @@ public void dfs(List<Integer> masks, int pos, int mask) {
5455
dfs(masks,pos +1,mask);
5556
}
5657
}
58+
59+
classSolution1extendsSolution {
60+
@Override
61+
publicintmaxLength(List<String>arr) {
62+
List<HashSet<Character>>all =newArrayList<>();
63+
all.add(newHashSet<>());
64+
intans =0;
65+
for (Stringstr :arr) {
66+
for (inti =0;i <all.size();i++) {
67+
HashSet<Character>s =all.get(i);
68+
// 用一个哈希集合中的元素去构建新的哈希集合
69+
HashSet<Character>tmp =newHashSet<>(all.get(i));
70+
for (Characterc :str.toCharArray()) {
71+
tmp.add(c);
72+
}
73+
// 当前集合中的字符串和当前字符串没有重复
74+
if (tmp.size() ==s.size() +str.length()) {
75+
all.add(tmp);
76+
ans =Math.max(ans,tmp.size());
77+
}
78+
}
79+
}
80+
returnans;
81+
}
82+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp