프로그래머스/level 3 6

[프로그래머스] 이중우선순위큐

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges import heapq def solution(operations): answer = [] while operations: o, num = operations.pop(0).split() if o == "I": heapq.heappush(answer, int(num)) elif answer and o == "D" and int(num) > 0: answer.pop() elif answer and o == "D" and int(num) < 0: answer.pop(0) answer.sort() if answer: return [answer[-1], answer[0]] else: return [..

[프로그래머스] 베스트 앨범

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges 사실 조건은 4개로 보아야 함 오랜만에 +2점...! from functools import cmp_to_key def cmp_sum(x, y): return y[1] - x[1] def cmp_by_condition(x, y): x_index, x_play = x y_index, y_play = y if x_play == y_play: return x_index - y_index else: return y_play - x_play def solution(genres, plays): answer = [] _dict1 = dict() _dict2 = dict() for i, (genre, p..

[프로그래머스] 순위

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges ** 시도중 from collections import deque def solution(n, results): win_graph = [ [] for i in range(n + 1) ] lose_graph = [ [] for i in range(n + 1) ] wn_c = [ 0 for i in range(n + 1) ] for result in results: win_graph[result[0]].append(result[1]) lose_graph[result[1]].append(result[0]) queue = deque() queue.append(results[0][0]) answer..

[프로그래머스] 가장 먼 노드

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges from collections import deque def solution(n, edge): graph = [[] for i in range(n + 1)] node_count = [0 for i in range(n + 1)] for i, e in enumerate(edge): graph[e[0]].append(e[1]) graph[e[1]].append(e[0]) node_count[1] = 1 queue = deque() queue.append(1) while queue: now = queue.popleft() for g in graph[now]: if node_count[g] == 0..

[프로그래머스] 정수 삼각형

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges def solution(triangle): answer = triangle[0][0] if len(triangle) == 1: return answer d = [[0] * (i + 1) for i in range(len(triangle))] d[0][0] = triangle[0][0] for i in range(1, len(triangle)): for j in range(len(triangle[i])): if j == 0: # 삼각형 i열 0번째 d[i][j] = d[i-1][j] + triangle[i][j]; elif j == i: # 삼각형 i열 마지막 d[i][j] = d[i-1][..

[프로그래머스] 헤비 유저가 소유한 장소 (MySQL)

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges MySQL 문제들은 아쉽게도 점수가 없어 순위에 영향을 주지 않는다. SELECT ID, NAME, HOST_ID FROM PLACES WHERE HOST_ID IN ( SELECT HOST_ID FROM PLACES GROUP BY HOST_ID HAVING COUNT(*) > 1 ) ORDER BY ID ASC; 참고: https://thispointer.com/mysql-select-where-count-is-greater-than-one-solved/ MySQL Select where Count is greater than one [Solved] – thispointer.com In..

반응형