I am solving an easy question but having this error at solving for "()[]{}".
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order.
class Solution:
def isValid(self, s: str) -> bool:
matchdict = {'(': ')', '{': '}', '[': ']'}
slen = len(s)
if slen%2!=0:
return False
for i in range(slen // 2):
if (matchdict[s[i]] != s[slen-i-1] and (matchdict[s[2*i]] != s[2*i+1])):
return False
return True
KeyError: ')'
if (matchdict[s[i]] != s[slen-i-1] and (matchdict[s[2*i]] != s[2*i+1])):
Line 9 in isValid (Solution.py)
ret = Solution().isValid(param_1)
Line 32 in _driver (Solution.py)
_driver()
Line 43 in <module> (Solution.py)
if slen%2!=0:->if slen % 2:invalidone - such as[as I can tell. Side note - dont useopenfunction as the variable name.