Created
December 12, 2020 06:08
-
-
Save Desolve/3c225e5679bc20afbbef6839ca86f140 to your computer and use it in GitHub Desktop.
1544 Make The String Great
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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