Coding Test

Coding Test

[Python] 백준 11557 - Yangjojang of The Year

문제https://www.acmicpc.net/problem/11557 해설해시 맵을 이용하여 해결하였다. def solution(n): for _ in range(n): univ_cnt = int(input()) univ_map = dict() for _ in range(univ_cnt): univ, bottle = input().split() bottle = int(bottle) if univ in univ_map: univ_map[univ] += bottle else: univ_map[univ] = bottle..

Coding Test

[Python] 프로그래머스 - 다리를 지나는 트럭

문제https://school.programmers.co.kr/learn/courses/30/lessons/42583 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 해설두개의 큐(현재 코드에선 리스트로 구현)를 활용하여 해결할 수 있는 문제였다. def solution(bridge_length, weight, truck_weights): second = 0 on_bridge_car = [] on_bridge_sec = [] while truck_weights or on_bridge_car: second += 1 pass_state = False ..

Coding Test

[Python] 백준 11004 - K번째 수

문제https://www.acmicpc.net/problem/11004 해설최소 힙을 사용하는 문제였다. import heapqdef solution(target, heap): heapq.heapify(heap) for _ in range(target-1): heapq.heappop(heap) return heap[0]n, k = map(int, input().split())order = list(map(int, input().split()))print(solution(k, order))

Coding Test

[Python] 프로그래머스 - 더 맵게

문제https://school.programmers.co.kr/learn/courses/30/lessons/42626?language=python3 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 해설최소 힙을 활용하는 문제이다. import heapqdef solution(scoville, K): heapq.heapify(scoville) answer = 0 while scoville[0]

Coding Test

[Python] 백준 1417 - 국회의원 선거

문제https://www.acmicpc.net/problem/1417 해설최대 힙을 활용하는 문제였다. import heapqdef solution(target, heap): heapq.heapify(heap) if not len(heap): return 0 answer = 0 while target

Coding Test

[Python] leetcode 2500 - Delete Greatest Value in Each Row

문제https://leetcode.com/problems/delete-greatest-value-in-each-row/ 해설2차원 상태의 배열에서 최대 힙을 적용하는 문제이다.  Solution 1.아래는 heap을 이용하여 해결한 방식이다. import heapqclass Solution: def deleteGreatestValue(self, grid: List[List[int]]) -> int: answer = 0 while len(grid[0]) != 0: matrix = [] deleted_comp = [] for row in grid: row = [c if c  Solution 2..

loading