Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def valid_parentheses(string):
- temp = []
- for ch in string:
- if ch == '(' or ch == ')':
- temp.append(ch)
- remove = True
- count = 0
- result = []
- if not len(temp)%2 == 0:
- return False
- while remove:
- if temp:
- if temp[0] == ')':
- return False
- if count < len(temp):
- if temp[count]=='(':
- result.append(temp[count])
- count = count + 1
- elif temp[count] == ')':
- if result and result[-1] == '(':
- del result[-1]
- del temp[count]
- del temp[count - 1]
- count = 0
- else:
- remove = False
- if len(result)==0:
- return True
- else:
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement