STUDY/Algorithm 402

[프로그래머스] LEVEL2 더맵게, python3, 힙,Heap

1차 시도 def solution(scoville, K): answer = 0 while True: scoville.sort() if scoville[0]==0 and scoville[1]==0: return -1 min1=scoville.pop(0) min2=scoville.pop(1) mixed=min1+min2*2 scoville.insert(0,mixed) answer+=1 if min(scoville)>=K: break return answer Heap에 관한 설명 https://gmlwjd9405.github.io/2018/05/10/data-structure-heap.html [자료구조] 힙(heap)이란 - Heee's Development Blog Step by step goes a lo..

STUDY/Algorithm 2019.11.06

[프로그래머스] LEVEL2 조이스틱,python3, 탐욕법(greedy)

1차시도 def solution(name): answer = 0 init="A"*len(name) for i in range(len(name)):# ascii: A=65 Z=90 if ord(name[i]) == 65: pass else: tmp=ord(name[i]) - 65 #print(tmp) if tmp>13: answer+=26-tmp else: answer+=tmp return answer 2차시도 def solution(name): answer = 0 len_name=len(name) init="A"*len_name chk=[] for i in range(len_name):# ascii: A=65 Z=90 if ord(name[i]) == 65: chk.append(1) pass else: ..

STUDY/Algorithm 2019.11.04

[프로그래머스] LEVEL2 다리를 지나는 트럭,python3, 스택/큐

def solution(bridge_length, weight, truck_weights): answer = 0 ing=[] # 다리를 건너는 트럭 cnt=[] # 트럭당 지난 거리 ed=[] # 다리를 지난 트력 while 1: if (truck_weights == []) and (ing == []): break answer+=1 # count total time for i in range(len(cnt)): # decrease the times of trucks above the bridge cnt[i]-=1 if (cnt!=[])and(cnt[0]==0): ed.append(ing[0]) del cnt[0] del ing[0] if (sum(ing) max_weight: bridge.append(0..

STUDY/Algorithm 2019.10.22