package com.fishercoder.solutions;

/**
 * 844. Backspace String Compare
 *
 * Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.
 *
 * Example 1:
 * Input: S = "ab#c", T = "ad#c"
 * Output: true
 * Explanation: Both S and T become "ac".
 *
 *  Example 2:
 * Input: S = "ab##", T = "c#d#"
 * Output: true
 * Explanation: Both S and T become "".
 *
 *  Example 3:
 * Input: S = "a##c", T = "#a#c"
 * Output: true
 * Explanation: Both S and T become "c".
 *
 * Example 4:
 * Input: S = "a#c", T = "b"
 * Output: false
 * Explanation: S becomes "c" while T becomes "b".
 * Note:
 *
 * 1 <= S.length <= 200
 * 1 <= T.length <= 200
 * S and T only contain lowercase letters and '#' characters.
 * Follow up:
 *
 * Can you solve it in O(N) time and O(1) space?
 */
public class _844 {
  public static class Solution1 {
    public boolean backspaceCompare(String S, String T) {
      String processedS = process(S);
      String processedT = process(T);
      return processedS.equals(processedT);
    }

    private String process(String str) {
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < str.length(); i++) {
        if (str.charAt(i) == '#') {
          if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
          }
        } else {
          sb.append(str.charAt(i));
        }
      }
      return sb.reverse().toString();
    }
  }
}

@@ -33,808 +33,8 @@
 s;%0A%0A
-/**%0A * 844. Backspace String Compare%0A *%0A * Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.%0A *%0A * Example 1:%0A * Input: S = %22ab#c%22, T = %22ad#c%22%0A * Output: true%0A * Explanation: Both S and T become %22ac%22.%0A *%0A *  Example 2:%0A * Input: S = %22ab##%22, T = %22c#d#%22%0A * Output: true%0A * Explanation: Both S and T become %22%22.%0A *%0A *  Example 3:%0A * Input: S = %22a##c%22, T = %22#a#c%22%0A * Output: true%0A * Explanation: Both S and T become %22c%22.%0A *%0A * Example 4:%0A * Input: S = %22a#c%22, T = %22b%22%0A * Output: false%0A * Explanation: S becomes %22c%22 while T becomes %22b%22.%0A * Note:%0A *%0A * 1 %3C= S.length %3C= 200%0A * 1 %3C= T.length %3C= 200%0A * S and T only contain lowercase letters and '#' characters.%0A * Follow up:%0A *%0A * Can you solve it in O(N) time and O(1) space?%0A */%0A
 publ
@@ -49,16 +49,18 @@
  _844 %7B%0A
+  
   public
@@ -85,16 +85,20 @@
 tion1 %7B%0A
+    
     publ
@@ -143,24 +143,30 @@
 String T) %7B%0A
+      
       String
@@ -191,16 +191,22 @@
 ess(S);%0A
+      
       St
@@ -237,24 +237,30 @@
 s(T);%0A      
+  
+    
 return proce
@@ -293,11 +293,19 @@
     
+   
+ 
 %7D%0A%0A
+    
     
@@ -343,24 +343,30 @@
 tr) %7B%0A      
+  
+    
 StringBuilde
@@ -399,16 +399,22 @@
 ;%0A      
+   
+   
 for (int
@@ -442,24 +442,32 @@
 h(); i++) %7B%0A
+        
         if (
@@ -496,24 +496,34 @@
 %7B%0A          
+    
+      
 if (sb.lengt
@@ -545,16 +545,28 @@
         
+        
+    
 sb.delet
@@ -591,16 +591,26 @@
 ) - 1);%0A
+          
         
@@ -621,16 +621,24 @@
         
+ 
+       
 %7D else %7B
@@ -648,16 +648,26 @@
         
+       
+   
 sb.appen
@@ -692,24 +692,46 @@
         
+        %7D%0A            
 %7D%0A      
 %7D%0A      
@@ -718,26 +718,24 @@
     %7D%0A      
-%7D%0A
       return
@@ -764,16 +764,22 @@
 ();%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 844