Don't know why my solution doesn't work. Can anybody help?
Anonymous User
32

Hi,
I have a potential solution for '20. Valid Parentheses', but I don't know why these codes don't work out. Can anybody help me know what's wrong? Thanks!
'''
class Solution:
def isValid(self, s: str) -> bool:
paren = {
'(': 1,
')': 2,
'{': 3,
'}': 4,
'[': 5,
']': 6,
}
if len(s) % 2 != 0:
return 'false'
else:
for i, value in enumerate(s):
x = len(s)-1-i
d = paren[s[x]] - paren[value]
if d == 1:
isValid = True
else:
return 'false'
if isValid is True:
return 'true'
else:
return 'false'
'''

Comments (1)