2026-04-29 16:07:40 +09:00

21 lines
374 B
Python

s = "(()("
def solution(s) :
from collections import deque
stack = deque()
for c in s :
if c == "(" :
stack.append(c)
elif c == ")" :
if not stack :
return False
else :
stack.pop()
if stack :
return False
else :
return True
print(solution(s))