File tree 3 files changed +16
-19
lines changed
solution/1500-1599/1576.Replace All #003F's to Avoid Consecutive Repeating Characters
3 files changed +16
-19
lines changed Original file line number Diff line number Diff line change @@ -87,17 +87,16 @@ class Solution:
87
87
88
88
``` java
89
89
class Solution {
90
- public String modifyString (String s ) {
90
+ public String modifyString (String s ) {
91
91
char [] chars = s. toCharArray();
92
-
93
92
for (int i = 0 ; i < chars. length; i++ ) {
94
93
if (chars[i] == ' ?' ) {
95
- // 前面的字符
94
+ // 前面的字符
96
95
char ahead = i == 0 ? ' ' : chars[i - 1 ];
97
- // 最后的字符
98
- char behind = i == chars. length - 1 ? ' ' : chars[i + 1 ];
96
+ // 后面的字符
97
+ char behind = i == chars. length - 1 ? ' ' : chars[i + 1 ];
99
98
char temp = ' a' ;
100
- while (temp == ahead || temp == behind ) {
99
+ while (temp == ahead || temp == behind) {
101
100
temp++ ;
102
101
}
103
102
chars[i] = temp;
Original file line number Diff line number Diff line change @@ -82,17 +82,16 @@ class Solution:
82
82
83
83
``` java
84
84
class Solution {
85
- public String modifyString (String s ) {
85
+ public String modifyString (String s ) {
86
86
char [] chars = s. toCharArray();
87
-
88
87
for (int i = 0 ; i < chars. length; i++ ) {
89
88
if (chars[i] == ' ?' ) {
90
- // 前面的字符
89
+ // 前面的字符
91
90
char ahead = i == 0 ? ' ' : chars[i - 1 ];
92
- // 最后的字符
93
- char behind = i == chars. length - 1 ? ' ' : chars[i + 1 ];
91
+ // 后面的字符
92
+ char behind = i == chars. length - 1 ? ' ' : chars[i + 1 ];
94
93
char temp = ' a' ;
95
- while (temp == ahead || temp == behind ) {
94
+ while (temp == ahead || temp == behind) {
96
95
temp++ ;
97
96
}
98
97
chars[i] = temp;
Original file line number Diff line number Diff line change 1
1
class Solution {
2
- public String modifyString (String s ) {
2
+ public String modifyString (String s ) {
3
3
char [] chars = s .toCharArray ();
4
-
5
4
for (int i = 0 ; i < chars .length ; i ++) {
6
5
if (chars [i ] == '?' ) {
7
- // 前面的字符
6
+ // 前面的字符
8
7
char ahead = i == 0 ? ' ' : chars [i - 1 ];
9
- // 最后的字符
10
- char behind = i == chars .length - 1 ? ' ' : chars [i + 1 ];
8
+ // 后面的字符
9
+ char behind = i == chars .length - 1 ? ' ' : chars [i + 1 ];
11
10
char temp = 'a' ;
12
- while (temp == ahead || temp == behind ) {
11
+ while (temp == ahead || temp == behind ) {
13
12
temp ++;
14
13
}
15
14
chars [i ] = temp ;
16
15
}
17
16
}
18
17
return new String (chars );
19
18
}
20
- }
19
+ }
You can’t perform that action at this time.
0 commit comments