-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValid_Parantheses
More file actions
26 lines (24 loc) · 941 Bytes
/
Valid_Parantheses
File metadata and controls
26 lines (24 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#Date: 2/15/2025
#Author: Murilo Ferreira Lopes
#Code Goal: Answer for 'Valid Parantheses' problem in NeetCode
class Solution:
def isValid(self, s: str) -> bool:
#This represents stack where we'll keep track of parantheses ordering
data = []
#iterate through each character in string and add its negation to stack or return false if parantheses don't match, return true in the end of function otherwise
for c in s:
print(c)
if c == '(':
data.append(')')
elif c == '[':
data.append(']')
elif c == '{':
data.append('}')
elif len(data) == 0 or data[-1] is not c:
return False
else:
data.remove(data[-1])
#Check to see if all parantheses partners have been removed from stack
if len(data) > 0:
return False
return True