본문 바로가기

python185

[LEET CODE] 706. Design HashMap # Problem Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: MyHashMap() initializes the object with an empty map. void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value. int get(int key) returns the value to which the specified key is mapped, or -1 if this map c.. 2021. 4. 5.
[코딩 + 알고리즘 완주반] 18일차. 병합정렬 (merge sort) # 병합 정렬 재귀 용법을 사용한 정렬 알고리즘 리스트를 반으로 잘라 나눈 후 재귀적으로 병합 정렬 부분 리스트를 다시 하나의 정렬된 리스트로 합병 # 알고리즘 구현 # 병합하기 def merge(left,right): lp = 0 rp = 0 merged=list() # left,right 둘다 데이터 있을 때 while len(left) >lp and len(right) >rp : if left[lp]>right[rp]: merged.append(right[rp]) rp+=1 else: merged.append(left[lp]) lp+=1 # left에만 데이터 남아있을 때 while len(left) > lp : merged.append(left[lp]) lp+=1 # right에만 데이터 남아있을.. 2021. 4. 4.
[코딩 + 알고리즘 완주반] 18일차. 퀵 정렬 # 퀵 정렬 기준점을 정해서 기준점보다 작은 데이터는 왼쪽, 큰 데이터는 오른쪽으로 모으는 함수 작성 각 왼쪽, 오른쪽은 재귀 용법을 사용해서 반복 return qsort(left) + [pivot] + qsort(right) #퀵 정렬 구현 def qsort(data): if len(data) data[index]: left.append(data[index]) else: right.append(data[index]) return qsort(left) + [pivot] + qsort(right) # 리스트 컴프리헨션 사용 def qsort(data): if len(data) item ] right = [ item for item in data[1:] if pivot 2021. 4. 4.
❗️[LEET CODE] 23. Merge k Sorted Lists ( k개 정렬 리스트 병합) # Problem You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Constraints: k == lists.length 0 2021. 4. 1.
❗️[LEET CODE] 641. Design Circular Deque # Problem Design your implementation of the circular double-ended queue (deque). Your implementation should support following operations: MyCircularDeque(k): Constructor, set the size of the deque to be k. insertFront(): Adds an item at the front of Deque. Return true if the operation is successful. insertLast(): Adds an item at the rear of Deque. Return true if the operation is successful. dele.. 2021. 3. 31.
[코딩 + 알고리즘 완주반] 17일차. 재귀용법, 동적계획법과 분할정복 # 재귀 용법 함수 안에서 동일한 함수를 호출 # 일반적인 형태 # 일반적인 형태1 def function(입력): if 입력 > 일정값: # 입력이 일정 값 이상이면 return function(입력 - 1) # 입력보다 작은 값 else: return 일정값, 입력값, 또는 특정값 # 재귀 호출 종료 # 일반적인 형태2 def function(입력): if 입력 2021. 3. 31.
반응형