1666. Make The String Great
My accepted Python solution to LeetCode problem 1666, Make The String Great, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.6MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.6MB, accepted 2025-12-30.
class Solution:
def makeGood(self, s: str) -> str:
stack = []
for c in s:
if stack and abs(ord(stack[-1]) - ord(c)) == 32:
stack.pop()
else:
stack.append(c)
return ''.join(stack)