We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0012f75 commit 006bfebCopy full SHA for 006bfeb
src/main/java/g3401_3500/s3435_frequencies_of_shortest_supersequences/Solution.java
@@ -49,10 +49,7 @@ public List<List<Integer>> supersequences(String[] words) {
49
continue;
50
}
51
int size = Integer.bitCount(s);
52
- if (size > best) {
53
- continue;
54
- }
55
- if (!hasCycle(s)) {
+ if (size <= best && !hasCycle(s)) {
56
if (size < best) {
57
best = size;
58
goodSets.clear();
@@ -83,10 +80,8 @@ public List<List<Integer>> supersequences(String[] words) {
83
80
private boolean hasCycle(int mask) {
84
81
int[] color = new int[m];
85
82
for (int i = 0; i < m; i++) {
86
- if (((mask >> i) & 1) == 0 && color[i] == 0) {
87
- if (dfs(i, color, mask)) {
88
- return true;
89
+ if (((mask >> i) & 1) == 0 && color[i] == 0 && dfs(i, color, mask)) {
+ return true;
90
91
92
return false;
0 commit comments