Skip to content

Commit 7ccf868

Browse files
committed
Fixed sonar warnings.
1 parent 5dd4ee1 commit 7ccf868

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/main/java/g0401_0500/s0488_zuma_game/Solution.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88
import java.util.Set;
99

10+
@SuppressWarnings("java:S135")
1011
public class Solution {
1112
public int findMinStep(String board, String hand) {
1213
List<Character> boardList = new ArrayList<>();
@@ -17,8 +18,7 @@ public int findMinStep(String board, String hand) {
1718
for (char c : hand.toCharArray()) {
1819
handList.add(c);
1920
}
20-
int res = findMinStep(boardList, handList);
21-
return res;
21+
return findMinStep(boardList, handList);
2222
}
2323

2424
private int findMinStep(List<Character> boardList, List<Character> handList) {
@@ -36,7 +36,7 @@ private int findMinStep(List<Character> boardList, List<Character> handList) {
3636
Set<Character> duplicate = new HashSet<>();
3737
for (int handListIndex = 0; handListIndex < handList.size(); handListIndex++) {
3838
if (boardListIndex > 0
39-
&& boardList.get(boardListIndex - 1) == handList.get(handListIndex)) {
39+
&& boardList.get(boardListIndex - 1).equals(handList.get(handListIndex))) {
4040
continue;
4141
}
4242
if (duplicate.contains(handList.get(handListIndex))) {
@@ -46,18 +46,21 @@ private int findMinStep(List<Character> boardList, List<Character> handList) {
4646
}
4747
boolean goodCase1 =
4848
(boardListIndex < boardList.size()
49-
&& boardList.get(boardListIndex) == handList.get(handListIndex));
49+
&& boardList
50+
.get(boardListIndex)
51+
.equals(handList.get(handListIndex)));
5052
boolean goodCase2 =
5153
(boardListIndex > 0
5254
&& boardListIndex < boardList.size()
53-
&& boardList.get(boardListIndex - 1)
54-
== boardList.get(boardListIndex)
55-
&& boardList.get(boardListIndex - 1)
56-
!= handList.get(handListIndex));
55+
&& boardList
56+
.get(boardListIndex - 1)
57+
.equals(boardList.get(boardListIndex))
58+
&& !boardList
59+
.get(boardListIndex - 1)
60+
.equals(handList.get(handListIndex)));
5761
if (!goodCase1 && !goodCase2) {
5862
continue;
5963
}
60-
6164
List<Character> boardListClone = new ArrayList<>(boardList);
6265
List<Character> handListClone = new ArrayList<>(handList);
6366
boardListClone.add(boardListIndex, handListClone.remove(handListIndex));
@@ -82,7 +85,7 @@ public void cleanup(List<Character> boardList) {
8285
for (int i = 0; i < boardList.size() - 2; i++) {
8386
int repeatLen = 1;
8487
for (int j = i + 1; j < boardList.size(); j++) {
85-
if (boardList.get(j) == boardList.get(j - 1)) {
88+
if (boardList.get(j).equals(boardList.get(j - 1))) {
8689
repeatLen++;
8790
} else {
8891
break;

src/main/java/g0401_0500/s0491_increasing_subsequences/Solution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88
import java.util.Set;
99

10+
@SuppressWarnings("java:S5413")
1011
public class Solution {
1112
public List<List<Integer>> findSubsequences(int[] nums) {
1213
if (nums == null || nums.length == 1) {
@@ -23,7 +24,7 @@ private Set<List<Integer>> backtracking(
2324
answer.add(new ArrayList<>(currList));
2425
}
2526
for (int i = start; i < nums.length; i++) {
26-
if (currList.size() == 0 || currList.get(currList.size() - 1) <= nums[i]) {
27+
if (currList.isEmpty() || currList.get(currList.size() - 1) <= nums[i]) {
2728
currList.add(nums[i]);
2829
backtracking(nums, i + 1, currList, answer);
2930
currList.remove(currList.size() - 1);

0 commit comments

Comments
 (0)