CS/문제 풀이2023. 1. 31. 20:41표현 가능한 이진트리

풀이 과정은 다음과 같다 들어온 숫자를 이진트리 노드 갯수 (2**N - 1) 형태의 이진수로 변경한다 ex) 42 -> 0101010 DFS 를 활용해 부모가 0인데 자식이 1인 노드를 찾는다. 있으면 return 0 없으면 return 1 import math def DFS(binary, parent): # print(binary, parent) if len(binary) == 1: if parent == 0 and int(binary) == 1: # print("return 0 " ) return 0 else : return 1 mid_index = math.floor(len(binary)/2) root = int(binary[mid_index]) if parent == 0 and root == 1..

CS/문제 풀이2023. 1. 30. 22:00인사고과

def solution(scores): answer = 0 if len(scores) == 1: return 1 wanho_score = scores[0][1] + scores[0][0] # sorted_scores = sorted(scores, key=lambda x : (-x[0], -x[1])) sorted_scores = sorted(scores, key=lambda x : (-x[0], x[1])) # before_attitude_score = sorted_scores[0][0] max_reputation_score = sorted_scores[0][1] incentive_list = [] for attitude_score, reputation_score in sorted_scores: if r..

프로그래머스 레벨 1 다 풀고
CS/문제 풀이2022. 8. 11. 19:18프로그래머스 레벨 1 다 풀고

코딩 테스트 쓰면 좋은 함수 map - map(function_name, list_name(=iterable) : iterable한 요소에 function을 적용시킨다. 주로 타입 캐스팅을 하는데 용이하게 사용했다. 예를 들면 int, str 등의 경우를 빠르게 코드를 작성할 수 있다. zip - 여러 iterable 한 객체를 for 문 돌릴 때 하나씩 꺼내온다, index를 통해 접근하는 것보다 직관적이다 for a,b,c in zip(a_list, b_list, c_list) : d = a+b+c print(d) split() - 문자열을 파싱할 때, 파라미터로 넣은 문자열을 기준으로 잘라서 iterable 한 객체를 반환한다. hello_string = "Hello World, nice to me..

CS/문제 풀이2022. 1. 21. 23:23프로그래머스 - 이중순위큐,k 번째 수

https://programmers.co.kr/learn/courses/30/lessons/42628 코딩테스트 연습 - 이중우선순위큐 programmers.co.kr import heapq class Double_heap: def __init__(self): self.maxheap = list() self.minheap = list() def push(self, number): heapq.heappush(self.maxheap, -number) heapq.heappush(self.minheap, number) def pop_max(self): if self.maxheap and self.minheap : max_out = -heapq.heappop(self.maxheap) self.minheap.rem..

CS/문제 풀이2022. 1. 19. 19:27프로그래머스 - 다리를 지나는 트럭, 주식 가격, 더 맵게

https://programmers.co.kr/learn/courses/30/lessons/42583 코딩테스트 연습 - 다리를 지나는 트럭 트럭 여러 대가 강을 가로지르는 일차선 다리를 정해진 순으로 건너려 합니다. 모든 트럭이 다리를 건너려면 최소 몇 초가 걸리는지 알아내야 합니다. 다리에는 트럭이 최대 bridge_length대 올라갈 programmers.co.kr class Truck : def __init__(self, weight): self.weight = weight self.time =0 def solution(bridge_length, weight, truck_weights): bridge = list() result_queue = [] result_case_number = len(t..

image