Skip to content

Commit

Permalink
#10 : 11279_최대 힙
Browse files Browse the repository at this point in the history
  • Loading branch information
ziy00n committed Apr 26, 2023
1 parent 000f587 commit 85d858d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 이티지윤/11279_최대 힙.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# for문 안의 num = int(input()) # 이 방법 시간초과=> 반복문으로 여러 줄 받을 때 input()은 시간초과 발생

import heapq, sys

heap = []
n = int(input())

for i in range(n):
num = int(sys.stdin.readline()) # 한 줄 입력 받아 정수형으로 형변환
if num == 0: # 0 입력되면
if heap: # 힙에 요소 있을 때 가장 큰 값 첫번째 루트 노드 삭제
print(heapq.heappop(heap)[1])
else:# 비어있을 때 0 출력
print(0)
else: # 자연수 입력되면
heapq.heappush(heap, (-num, num)) # (우선순위, 값)

19 changes: 19 additions & 0 deletions 이티지윤/1966_프린터 큐.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
num = int(input())

for i in range(num):
N, M = map(int, input().split())
queue = list(map(int, input().strip().split()))
queue = [(v, idx) for idx, v in enumerate(queue)]

order = 0

while True:
if max(queue)[0] == queue[0][0]:
order += 1
if queue[0][1] == M:
print(order)
break
else:
queue.pop(0)
else:
queue.append(queue.pop(0))
17 changes: 17 additions & 0 deletions 이티지윤/프로그래머스_전화번호 목록.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def solution(phone_book):
answer = True
hash = {}

for i in phone_book:
hash[i] = 0

for i in phone_book:
print(i)
temp = ''
for j in i:
temp += j
if temp in hash and temp != i:
answer = False
return answer

print(solution(["34", "3456", "789"]))

0 comments on commit 85d858d

Please sign in to comment.