Skip to content

Commit 006bfeb

Browse files
committed
Fixed sonar
1 parent 0012f75 commit 006bfeb

File tree

1 file changed

+3
-8
lines changed
  • src/main/java/g3401_3500/s3435_frequencies_of_shortest_supersequences

1 file changed

+3
-8
lines changed

src/main/java/g3401_3500/s3435_frequencies_of_shortest_supersequences/Solution.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ public List<List<Integer>> supersequences(String[] words) {
4949
continue;
5050
}
5151
int size = Integer.bitCount(s);
52-
if (size > best) {
53-
continue;
54-
}
55-
if (!hasCycle(s)) {
52+
if (size <= best && !hasCycle(s)) {
5653
if (size < best) {
5754
best = size;
5855
goodSets.clear();
@@ -83,10 +80,8 @@ public List<List<Integer>> supersequences(String[] words) {
8380
private boolean hasCycle(int mask) {
8481
int[] color = new int[m];
8582
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-
}
83+
if (((mask >> i) & 1) == 0 && color[i] == 0 && dfs(i, color, mask)) {
84+
return true;
9085
}
9186
}
9287
return false;

0 commit comments

Comments
 (0)