77import java .util .List ;
88import java .util .Set ;
99
10+ @ SuppressWarnings ("java:S135" )
1011public 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 ;
0 commit comments