File tree 1 file changed +9
-14
lines changed
src/main/java/g2001_2100/s2027_minimum_moves_to_convert_string
1 file changed +9
-14
lines changed Original file line number Diff line number Diff line change 1
1
package g2001_2100 .s2027_minimum_moves_to_convert_string ;
2
2
3
- // #Easy #String #Greedy #2022_05_25_Time_4_ms_(5.74%)_Space_42.1_MB_(37.50 %)
3
+ // #Easy #String #Greedy #2022_05_25_Time_0_ms_(100.00%)_Space_40_MB_(97.32 %)
4
4
5
5
public class Solution {
6
6
public int minimumMoves (String s ) {
7
- int moves = 0 ;
7
+ int r = 0 ;
8
8
int i = 0 ;
9
- while (i < s .length ()) {
10
- if (s .charAt (i ) == 'O' ) {
11
- i ++;
12
- continue ;
13
- }
14
- String candidate = i + 3 <= s .length () ? s .substring (i , i + 3 ) : s .substring (i );
15
- if (candidate .contains ("X" )) {
16
- moves ++;
17
- i += 3 ;
18
- } else {
19
- i ++;
9
+ char [] sArray = s .toCharArray ();
10
+ while (i < sArray .length ) {
11
+ if (sArray [i ] == 'X' ) {
12
+ r ++;
13
+ i += 2 ;
20
14
}
15
+ i ++;
21
16
}
22
- return moves ;
17
+ return r ;
23
18
}
24
19
}
You can’t perform that action at this time.
0 commit comments