python 80

[프로그래머스] LEVEL2 구명보트, python3, 탐욕법(greedy)

1차 시도 def solution(people, limit): answer = 0 people.sort() #print(people) while people!=[]: answer+=1 tmp1=people.pop() tmp2=limit-tmp1 #print(tmp1,tmp2,people) if people==[]: break elif tmp1==limit: continue elif tmp2tmp3: continue return answer 2차시도 def solution(people, limit): answer = 0 people.sort() while people!=[]: answer+=1 tmp=people.pop() remainder=limit-tmp if people==[]: break elif ..

STUDY/Algorithm 2019.11.14

[프로그래머스] LEVEL2 H-Index, python3, 정렬

문제가 이해가 안되었다. 질문하기에도 나랑 비슷한 사람들이 많아서 도움을 얻었는데 해당 테스트 케이스를 보니 이해가 갔다. test case: [22, 42] return value:2 알고리즘 공부할때 문제를 읽고 이해하는 능력도 많이 중요한것 같다. 1차 시도 def solution(citations): answer = 0 max_cit=max(citations) for n in range(max_cit): tmp=list(i for i in citations if i>=n) length=len(tmp) if n>length: answer=n-1 break return answer

STUDY/Algorithm 2019.11.14

[프로그래머스] LEVEL2 가장큰수, python3, 정렬

1차 시도 from itertools import permutations def solution(numbers): answer = '' ## permutation of elements of numbers numbers=list(map(str,numbers)) tmp=list(map(''.join, permutations(numbers))) answer=max(tmp) return answer 논리는 맞는거 같은데 permutation할때 시간이 오래 걸리는듯 하다. 2차시도 def solution(numbers): answer = '' tmp_nums=[] max_len=len(str(max(numbers))) for num in numbers: length=0 len_num=len(str(num)) t..

STUDY/Algorithm 2019.11.06

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