프로그래머스(파이썬)

    H-index → 논문을 적게 발표했지만, 인용된 수가 많은 good 케이스

    이해를 돕기 위해서 아래 설명을 덧붙인다. 해당 논문이 인용된 수 : [9, 7, 6, 1] 발표된 논문의 수 : [1, 2, 3, 4] return 3 해설 첫번째 경우를 살펴보면, 논문을 1개 발표했는데, "해당 논문"이 다른 곳에서 9번 인용되었다는 의미이므로 "good"이다라고 볼 수 있고, 마지막의 경우를 살펴보면, 논문을 4개 발표했는데, "해당 논문"은 다른 곳에서 1번 인용되었다는 의미이므로 'bad"라고 볼 수 있다. →우리의 목표는 인용된 수가 발표된 논문의 수와 같거나 인용된 수가 발표된 논문의 수보다 큰 "경우의 수"를 구하는 것이다. 즉 "good"인 경우를 찾겠다는 의미이다. 해당 논문이 인용된 수 : [15, 12, 10, 8, 6, 3, 2, 1] 발표된 논문 수) : [ 1..

    더 맵게 → heap★★

    나의 풀이 import heapq def solution(scoville, K): cnt=0 heap=[] for x in scoville: heapq.heappush(heap, x) if heap[0]>=K: return cnt while(len(heap)>1): 첫번째로 가장 작은 원소를 pop한다. min1=heapq.heappop(heap) 또 남아있는 것 중에서 가장 작은 원소를 pop한다. min2=heapq.heappop(heap) new_scoville=min1+(min2*2) heap.append(new_scoville) cnt+=1 if heap[0]>=K: return cnt return -1 힙(자료구조)의 활용 ▶ import heapq heap =[] heapq.heappush(..

    귤 고르기→ Counter() 함수, most_common()

    from collections import Counter def solution(k, tangerine): list=Counter(tangerine).most_common() #종류의 수 kind=1 sum=list[0][1] for i in range(len(list)-1): if sum>=k: return kind else: sum+=list[i+1][1] kind+=1 return kind

    k진수에서 소수 개수 구하기→ 10진수를 n진법, 소수 판별★,filter()함수★

    나의 풀이 import math #10진법을 k진법으로 변환 def solution(num, n): result = [] if num == 0: result.append(0) while num > 0: if num % n < 10: result.append(num % n) else: result.append(chr(num % n - 10 + ord('A'))) num //= n list_str1=join_split(result[::-1]) list_str1=list(filter(None, list_str1)) return counter(list_str1) #소수인지 판별 def isPrime(x): if x ==1: return False for i in range(2, int(math.sqrt(x))+..