class Solution:
def removeInvalidParentheses(self, s):
"""
:type s: str
:rtype: List[str]
"""
q = {s}
ret = set()
while True:
valid = filter(self.isValid, q)
if valid:
return valid
q = {s[:i] + s[i + 1:] for s in q for i in range(len(s))}
# def isValid(self, s):
# l = 0
# for c in s:
# if c == '(':
# l += 1
# elif c == ')':
#
# l -= 1
#
# if l < 0:
# return False
#
# return l == 0
def isValid(self,s):
s = filter('()'.count, s)
while '()' in s:
s = s.replace('()','')
return not s