Skip to content

Instantly share code, notes, and snippets.

@Desolve
Created December 12, 2020 06:08
Show Gist options
  • Save Desolve/3c225e5679bc20afbbef6839ca86f140 to your computer and use it in GitHub Desktop.
Save Desolve/3c225e5679bc20afbbef6839ca86f140 to your computer and use it in GitHub Desktop.
1544 Make The String Great
class Solution {
public String makeGood(String s) {
Stack<Character> st = new Stack<Character>();
StringBuilder res = new StringBuilder();
for (char c : s.toCharArray()) {
if (!st.isEmpty() && Math.abs(st.peek() - c) == 32) {
st.pop();
} else {
st.push(c);
}
}
while (!st.isEmpty()) res.append(st.pop());
return res.reverse().toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment