Removing Parentheses
class Solution:
def solve(self, s):
"""
first thought is we track ( and )
if we one is higher than the other, we remove it
"""
if not s:
return 0
total = 0
temp = 0
for p in s:
if p == "(":
total += 1
elif p == ")" and total:
# the and total means this only runs if total is more than 0
# so we only have ) if we have ( before it
total -= 1
else:
temp += 1
return total + tempLast updated