7
7
import java .util .List ;
8
8
import java .util .Set ;
9
9
10
+ @ SuppressWarnings ("java:S135" )
10
11
public class Solution {
11
12
public int findMinStep (String board , String hand ) {
12
13
List <Character > boardList = new ArrayList <>();
@@ -17,8 +18,7 @@ public int findMinStep(String board, String hand) {
17
18
for (char c : hand .toCharArray ()) {
18
19
handList .add (c );
19
20
}
20
- int res = findMinStep (boardList , handList );
21
- return res ;
21
+ return findMinStep (boardList , handList );
22
22
}
23
23
24
24
private int findMinStep (List <Character > boardList , List <Character > handList ) {
@@ -36,7 +36,7 @@ private int findMinStep(List<Character> boardList, List<Character> handList) {
36
36
Set <Character > duplicate = new HashSet <>();
37
37
for (int handListIndex = 0 ; handListIndex < handList .size (); handListIndex ++) {
38
38
if (boardListIndex > 0
39
- && boardList .get (boardListIndex - 1 ) == handList .get (handListIndex )) {
39
+ && boardList .get (boardListIndex - 1 ). equals ( handList .get (handListIndex ) )) {
40
40
continue ;
41
41
}
42
42
if (duplicate .contains (handList .get (handListIndex ))) {
@@ -46,18 +46,21 @@ private int findMinStep(List<Character> boardList, List<Character> handList) {
46
46
}
47
47
boolean goodCase1 =
48
48
(boardListIndex < boardList .size ()
49
- && boardList .get (boardListIndex ) == handList .get (handListIndex ));
49
+ && boardList
50
+ .get (boardListIndex )
51
+ .equals (handList .get (handListIndex )));
50
52
boolean goodCase2 =
51
53
(boardListIndex > 0
52
54
&& 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 )));
57
61
if (!goodCase1 && !goodCase2 ) {
58
62
continue ;
59
63
}
60
-
61
64
List <Character > boardListClone = new ArrayList <>(boardList );
62
65
List <Character > handListClone = new ArrayList <>(handList );
63
66
boardListClone .add (boardListIndex , handListClone .remove (handListIndex ));
@@ -82,7 +85,7 @@ public void cleanup(List<Character> boardList) {
82
85
for (int i = 0 ; i < boardList .size () - 2 ; i ++) {
83
86
int repeatLen = 1 ;
84
87
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 ) )) {
86
89
repeatLen ++;
87
90
} else {
88
91
break ;
0 commit comments