I'm trying to run a leetcode solution through a debugger so I can see how the solution works. Its number 20 on parenthesis. This is what I've plugged into the debugger..am I missing something?
class Solution:
def isValid(self, s: str) -> bool:
parenthesis = {"}":"{",
"]":"[",
")":"("
}
stack = []
for i in s:
if i in parenthesis:
if not stack or paren[i] != stack[-1]:
return False
else:
stack.pop()
else:
stack.append(i)
return stack == []
Solution.isValid("{[]}")
I've tried making an instance of the class but I still get the same issue.
CodePudding user response:
I think you should create the object of a class first.
sol = Solution()
print(sol.isValid("{[]}")
CodePudding user response:
Creating an Object a
of a Class Solution
Note you need to use print
statment for the output. without print
statement your console will show nothing.
class Solution:
def isValid(self, s: str) -> bool:
parenthesis = {"}":"{",
"]":"[",
")":"("
}
stack = []
for i in s:
if i in parenthesis:
if not stack or parenthesis[i] != stack[-1]:
return False
else:
stack.pop()
else:
stack.append(i)
return stack == []
a=Solution()
print(a.isValid("{[]}"))
Output:-
True