class Solution {
private Random random = new Random();
public Character findCandidate(Character ban1, Character ban2) {
Character ans = 'a';
while (ans == ban1 || ans == ban2) {
ans = (char)('a' + this.random.nextInt(26));
}
return ans;
}
public String modifyString(String s) {
char[] charArray = s.toCharArray();
for (int i = 0; i < charArray.length; i++) {
if (charArray[i] == '?') {
if (i == 0) {
if (i+1 < charArray.length) charArray[i] = findCandidate(charArray[i+1], null);
else charArray[i] = 'a';
}
else if (i == charArray.length - 1) charArray[i] = findCandidate(charArray[i-1], null);
else charArray[i] = findCandidate(charArray[i-1], charArray[i+1]);
}
}
return String.valueOf(charArray);
}
}