일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- next Link
- CSS
- 최적화
- typescript
- HTML
- 백준 스택 시간초과 python
- k for k
- Python
- 프론트엔드
- 자바스크립트
- 알고리즘
- 코딩테스트
- 파이어베이스
- JS
- TS
- 스택
- Android
- firebase
- react
- 안드로이드
- 리액트
- kotlin
- stdin vs input
- nodejs
- 파이썬
- 타입스크립트
- javascript
- 백준 스택
- C++
- NPM
- Today
- Total
목록stack (2)
sooleeandtomas

좀 쉬운 것 같아서 하나 더 풀기로 했다. 근데 이것도 거의 10분 컷이었다. 완전 쉬움 아까 살짝 맛본 class를 사용해보았다. import sys class stack: def __init__(self): self.L = [] def push(self, X): self.L.append(X) def pop(self): if len(self.L) == 0: return -1 else: self.L.pop() def sum(self): return sum(self.L) a = stack() N = int(sys.stdin.readline()) for i in range(N): L = list(map(str, sys.stdin.readline().strip().split())) if L[0] == "0":..

import sys def stack(n): stack_list = [] for _ in range(n): command = sys.stdin.readline() #input() 을 사용하게 되면 시간이 초과된다. if "push" in command: number = command.split(' ')[-1] stack_list.append(int(number)) if "top" in command: if len(stack_list) == 0: print(-1) else: print(stack_list[-1]) if "size" in command: print(len(stack_list)) if "pop" in command: if len(stack_list) == 0: print(-1) else: pr..