본문 바로가기
LEETCODE 46: PERMUTATIONS Link : https://leetcode.com/problems/permutations/ Python 더보기 1 2 3 4 5 6 7 8 9 10 11 12 class Solution: def DFS(self, extra, result, deapth): t_list = [] if len(extra) == 0: return [result[:]] for idx, val in enumerate(extra): result[deapth] = val; t_list += self.DFS(extra[:idx] + extra[idx + 1:], result, deapth + 1) return t_list def permute(self, nums: list[int]) -> list[list[int]]: return se.. 2021. 8. 5.
PROGRAMMERS 49189: 가장 먼 노드 Link : https://programmers.co.kr/learn/courses/30/lessons/49189 Python 더보기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 from collections import deque INF = int(1e9) def solution(n, edge): graph = [[] for _ in range(n)] que = deque() distance = [INF for _ in range(n)] visited = [False for _ in range(n)] for s, e in edge: s -= 1; e -= 1 graph[s].append(e) .. 2021. 7. 27.
PROGRAMMERS 42861: 섬 연결하기 Link : https://programmers.co.kr/learn/courses/30/lessons/42861 Python 더보기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 import heapq def prim(start, graph): result = 0 # 방문 확인을 위한 변수 visited = [False for _ in range(len(graph))] task = [] # 첫 시작점에서 갈 수 있는 범위를 등록 for end, cost in enumerate(graph[start]): if cost != 0: heapq.heappush(ta.. 2021. 7. 18.
PROGRAMMERS 42842: 카펫 Link : https://programmers.co.kr/learn/courses/30/lessons/42842 Python 더보기 1 2 3 4 5 6 7 8 def solution(brown, yellow): for x in range(2, 5000): for y in range(2, 2000000): if y > x: break if brown == 2 * x + 2 * (y - 2): if (x - 2) * (y - 2) == yellow: return [x, y] cs FeedBack cjw.git@gmail.com 2021. 7. 18.
PROGRAMMERS 77485: 행렬 테두리 회전하기 Link : https://programmers.co.kr/learn/courses/30/lessons/77485 Python 더보기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 def solution(rows, columns, queries): world = [[tx + (ty * columns) + 1 for tx in range(columns)] for ty in range(rows)] for i in range(len(queries)): for j in range(len(queries[0])): queries[i][j] -= 1 ans.. 2021. 6. 21.