100세까지 코딩
[백준] 12789번 도키도키 간식드리미 (파이썬) 본문
문제
나의 생각
- 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")
'코딩테스트 > 파이썬' 카테고리의 다른 글
[백준] 10989번 수 정렬하기3 (파이썬) (0) | 2024.01.27 |
---|---|
[백준] 4949번 균형잡힌 세상 (파이썬) (0) | 2024.01.27 |
[백준] 11650번 좌표 정렬하기 (파이썬) (0) | 2024.01.27 |
[백준] 1018번 체스판 다시 칠하기 (파이썬) (0) | 2024.01.19 |
[백준] 19532번 수학은 비대면강의입니다 (파이썬) (0) | 2024.01.19 |