-
Notifications
You must be signed in to change notification settings - Fork 378
Closed
Description
LeetCode Username
csambhav
Problem number, title, and link
20, Valid Parentheses,(https://leetcode.com/problems/valid-parentheses/)
Category of the bug
- Missing test Case (Incorrect/Inefficient Code getting accepted because of missing test cases)
Description of the bug
For the below Testcase
"()" at 8th index ']' is present. Ideally this should return False as there is no open bracket present in the stack, if stack is being used to implement. But even though my code is returning true, the correct output returned by Leetcode IDE is also true. And also all the test case are running.
Language used for code
Python3
Code used for Submit/Run operation
class Solution:
def isValid(self, s: str) -> bool:
stack = []
for char in s:
if char in ['(', '{', '[']:
stack.append(char)
elif char in [')', '}', ']']:
if not stack:
return False
elif char == ')':
if stack[-1]=='(':
stack.pop()
else:
return False
elif char == '}':
if stack[-1]=='{':
stack.pop()
else:
return False
elif char == ']':
if stack[-1]=='[':
stack.pop()
else:
return False
if stack:
return False
else:
return True
Expected behavior
For the testcase: "()" it should return false as per given description
Screenshots
Additional context
Metadata
Metadata
Assignees
Labels
No labels