-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
24 lines (22 loc) · 739 Bytes
/
main.py
File metadata and controls
24 lines (22 loc) · 739 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
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
stack = []
translation = {
"(": ")",
"[": "]",
"{": "}"
}
for char in s:
if char in translation:
stack.append(char)
elif char in translation.values(): # Se o caractere é um parêntese de fechamento
if not stack or translation[stack.pop()] != char:
return False
else: # Caso o caractere não seja um parêntese
return False
# Se o stack estiver vazio, todos os parênteses foram fechados corretamente
return not stack