# Process
# 1. Input operations
# 2. Iterate operations
# 2.1. Do operation with queue
# 3. Check queue for answer
# 4. Return answer
def solution(operations):
answer = []
array_queue = []
for operation in operations:
if operation.startswith('I'):
array_queue.append(int(operation[2:]))
elif operation.startswith('D') and len(array_queue) > 0:
if operation.endswith('-1'):
pop_smallest(array_queue)
else: # 1
pop_largest(array_queue)
print(array_queue)
if len(array_queue) > 1:
answer.append(pop_largest(array_queue))
answer.append(pop_smallest(array_queue))
else:
answer.append(0)
answer.append(0)
return answer
# priority queue 혹은 heapq 를 적용하려고 한참 하다가 그냥 만들어서 함
def pop_largest(array_queue):
max_index = 0
max_val = array_queue[max_index]
for i in range(1, len(array_queue)):
if array_queue[i] > max_val:
max_val = array_queue[i]
max_index = i
del array_queue[max_index]
return max_val
def pop_smallest(array_queue):
min_index = 0
min_val = array_queue[min_index]
for i in range(1, len(array_queue)):
if array_queue[i] < min_val:
min_val = array_queue[i]
min_index = i
del array_queue[min_index]
return min_val
힙 01 - 더맵게, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀이과정,
# Process # 1. Input scoville array and threshold K # 2. Make heap queue # 3. Iterate while all scoville is over K # 3.1. Check scoville (smallest one) # 3.1.1. If..
itdar.tistory.com
2020/10/07 - [Life/Item review] - Lenovo 레노보 씽크패드 Thinkpad 빨콩 무선키보드/블루투스/울트라나브2/트랙키보드 구매 후기
Lenovo 레노보 씽크패드 Thinkpad 빨콩 무선키보드/블루투스/울트라나브2/트랙키보드 구매 후기
빨콩 + 키감 + 무선 울트라나브2 를 기다리다가 최근 나왔길래 고민안하고 샀다. -> 가격 13만 5천원 내외였던 것 같은데 음.. 가성비는 그닥 -> 빨콩 예전 x1 이후에 간만에 빨콩을 쓰니 손이 잘 안
itdar.tistory.com
LeetCode #283 MoveZeroes #2. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제
LeetCode #283 MoveZeroes #2. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,..
itdar.tistory.com