level2 5

[프로그래머스] LEVEL2 타겟 넘버, python3, 깊이/너비 우선 탐색(DFS/BFS)

def solution(numbers, target): answer_list=[0] for i in numbers: temporary_list=[] #print("\nanswer_list:",answer_list) for j in answer_list: temporary_list.append(j+i) temporary_list.append(j-i) #print("tmp_list",temporary_list) answer_list=temporary_list #print("answer_list",answer_list) answer = answer_list.count(target) return answer 방법은 똑같았으나 구현하지 못해 내 코드는 아니지만 올린다.

STUDY/Algorithm 2019.11.20

[프로그래머스] 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