package com.fishercoder.solutions;

import java.util.Stack;

public class _1544 {
    public static class Solution1 {
        public String makeGood(String s) {
            Stack<Character> stack = new Stack<>();
            for (int i = 0; i < s.length() - 1; i++) {
                char c = s.charAt(i);
                if (stack.isEmpty()) {
                    stack.add(c);
                } else {
                    if (Character.toLowerCase(stack.peek()) == Character.toLowerCase(c)) {
                        if ((Character.isLowerCase(stack.peek()) && Character.isUpperCase(c))) {
                            stack.pop();
                        } else if (Character.isUpperCase(stack.peek()) && Character.isLowerCase(c)) {
                            stack.pop();
                        } else {
                            stack.add(c);
                        }
                    } else {
                        stack.add(c);
                    }
                }
            }
            char c = s.charAt(s.length() - 1);
            if (!stack.isEmpty() && Character.toLowerCase(stack.peek()) == Character.toLowerCase(c)) {
                if ((Character.isLowerCase(stack.peek()) && Character.isUpperCase(c))) {
                    stack.pop();
                } else if (Character.isUpperCase(stack.peek()) && Character.isLowerCase(c)) {
                    stack.pop();
                } else {
                    stack.add(c);
                }
            } else {
                stack.add(c);
            }
            StringBuilder sb = new StringBuilder();
            while (!stack.isEmpty()) {
                sb.append(stack.pop());
            }
            return sb.reverse().toString();
        }
    }
}

@@ -248,20 +248,16 @@
 length()
- - 1
 ; i++) %7B
@@ -991,549 +991,8 @@
   %7D%0A
-            char c = s.charAt(s.length() - 1);%0A            if (!stack.isEmpty() && Character.toLowerCase(stack.peek()) == Character.toLowerCase(c)) %7B%0A                if ((Character.isLowerCase(stack.peek()) && Character.isUpperCase(c))) %7B%0A                    stack.pop();%0A                %7D else if (Character.isUpperCase(stack.peek()) && Character.isLowerCase(c)) %7B%0A                    stack.pop();%0A                %7D else %7B%0A                    stack.add(c);%0A                %7D%0A            %7D else %7B%0A                stack.add(c);%0A            %7D%0A
     

refactor 1544