class Solution:
def isValid(self, s: str) -> bool:
if len(s) % 2 != 0:
return False
pair = {']':'[','}':'{',')':'('}
stack = []
for item in s:
if item in pair:
if not stack or stack[-1] != pair[item]:
return False
stack.pop()
else:
stack.append(item)
return True if not stack else False
class Solution:
def removeDuplicates(self, s: str) -> str:
stack = []
for i in s:
if stack and i == stack[-1]:
stack.pop()
else:
stack.append(i)
return ''.join(stack)