- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1576.java
27 lines (26 loc) · 976 Bytes
/
_1576.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
packagecom.fishercoder.solutions.secondthousand;
publicclass_1576 {
publicstaticclassSolution1 {
/*
* Each char could have at most two neighbors, so we only need to toggle between three character candidates to avoid repetition.
*/
publicStringmodifyString(Strings) {
char[] arr = s.toCharArray();
for (inti = 0; i < arr.length; i++) {
if (arr[i] == '?') {
for (intj = 0; j < 3; j++) {
if (i > 0 && arr[i - 1] == 'a' + j) {
continue;
} elseif (i < arr.length - 1 && arr[i + 1] == 'a' + j) {
continue;
} else {
arr[i] = (char) ('a' + j);
break;
}
}
}
}
returnString.valueOf(arr);
}
}
}