본문 바로가기

알고리즘&자료구조/Programmers

(5)
[프로그래머스] 코딩테스트 연습 > 스택/큐 > 프린터 def solution(priorities, location): answer = 0 index = [i for i in range(len(priorities))] max_num = max(priorities) while len(priorities) > 0: num = priorities.pop(0) i = index.pop(0) if num != max_num: priorities.append(num) index.append(i) else: answer += 1 if i == location: return answer max_num = max(priorities) return answer
[프로그래머스] 코딩테스트 연습 > 힙(Heap) > 더 맵게 import heapq def solution(scoville, K): answer = 0 heapq.heapify(scoville) while True: num1 = heapq.heappop(scoville) if num1 >= K : break if len(scoville) == 0: return -1 num2 = heapq.heappop(scoville) num = num1 + num2*2 heapq.heappush(scoville, num) answer += 1 return answer
[프로그래머스] 코딩테스트 연습 > 정렬 > K번째수 def solution(array, commands): answer = [] for com in commands: answer.append(sorted(array[com[0]-1:com[1]])[com[2]-1]) return answer def solution(array, commands): return list(map(lambda x:sorted(array[x[0]-1:x[1]])[x[2]-1], commands))
[프로그래머스] 코딩테스트 연습 > 스택/큐 > 기능개발 https://programmers.co.kr/learn/courses/30/lessons/42586 def solution(progresses, speeds): answer = [] left = [100-leftover for leftover in progresses] max = 0 for i in range(len(left)): if left[i]%speeds[i] != 0 : a = left[i]//speeds[i] + 1 else : a = left[i]//speeds[i] if a
[프로그래머스] 코딩테스트 연습 - 해시 문제 : https://programmers.co.kr/learn/courses/30/lessons/42576 코딩테스트 연습 - 완주하지 못한 선수수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수programmers.co.kr 나의 풀이 : def solution(participant, completion): dic_name = {} for runner in participant: if runner not in dic_name.keys(): dic_name[runner] = 0 dic_name[runner] += 1 ..