package leetcode;

/**
 * https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/
 */
public class Problem1576 {
    public String modifyString(String s) {
        String answer = "";
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '?') {
                for (char c = 'a'; c <= 'z'; c++) {
                    if (i - 1 >= 0) {
                        char prev = answer.charAt(i - 1);
                        if (prev == c) {
                            continue;
                        }
                    }
                    if (i + 1 < s.length()) {
                        char next = s.charAt(i + 1);
                        if (next == c) {
                            continue;
                        }
                    }
                    answer += c;
                    break;
                }
            } else {
                answer += s.charAt(i);
            }
        }
        return answer;
    }
}

@@ -194,16 +194,23 @@
   String
+Builder
  answer 
@@ -215,10 +215,27 @@
 r = 
-%22%22
+new StringBuilder()
 ;%0A  
@@ -848,13 +848,18 @@
 swer
- += c
+.append(c)
 ;%0A  
@@ -948,12 +948,16 @@
 swer
- += 
+.append(
 s.ch
@@ -963,16 +963,17 @@
 harAt(i)
+)
 ;%0A      
@@ -1011,16 +1011,27 @@
 n answer
+.toString()
 ;%0A    %7D%0A

Update problem 1576