PS/Python
[Python] 백준 11899번(괄호 끼워넣기) 문제 풀이
KwonYongHyeon
2022. 12. 11. 17:54
S = input()
stack = []
ans = 0
for char in S:
if char == "(":
stack.append(char)
continue
try:
stack.pop()
except:
ans += 1
print(ans+len(stack))
저번에 푼 9012번 문제와 상당히 유?사랄까 거의 똑같다. 코드를 진짜 조금만 수정했는데 바로 통과가 된다.
https://developer-next-to-you.tistory.com/302
[Python] 백준 9012번(괄호) 문제 풀이
for i in range(int(input())): stack = [] S = input() printed = False for char in S: if char == "(": stack.append(char) continue try: stack.pop() except: print("NO") printed = True break if printed: continue if len(stack) != 0: print("NO") continue print("Y
developer-next-to-you.tistory.com