Leetcode 1666 Solution

This article provides solution to leetcode question 1666 (make-the-string-great)

https://leetcode.com/problems/make-the-string-great

Solution

class Solution: def makeGood(self, s: str) -> str: if len(s) <= 1: return s
stack = []
i = 0 while i < len(s): if stack and int(abs(ord(s[i]) - ord(stack[-1]))) == ord('a') - ord('A'): stack.pop() else: stack.append(s[i])
i += 1
return "".join(stack)