코딩테스트/파이썬
[백준] 12789번 도키도키 간식드리미 (파이썬)
100세까지 코딩
2024. 1. 27. 11:17
문제
나의 생각
- cnt를 1부터 시작.
- stack에 입력받은 리스트를 순서대로 넣는다.
- 넣는 과정에서 만약 스택의 최상위가 cnt와 같으면 빼내고 cnt =+ 1을 해준다.
- 반복이 끝났는데 스택에 숫자가 남아있으면 false.
나의 풀이
import sys
N = int(sys.stdin.readline())
stack = []
num_list = list(map(int, sys.stdin.readline().split()))
cnt = 1
for data in num_list:
stack.append(data)
while stack and stack[-1] == cnt:
cnt += 1
stack.pop()
print("Sad") if stack else print("Nice")