Coding Test/Python

https://www.acmicpc.net/problem/15686 15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net 아이디어 우선 모든 집과 치킨 집의 좌표를 찾아준다. 치킨 집 M개를 선택한 경우를 모두 구해준다. (dfs 사용) 각 경우의 수에 해당하는 도시의 치킨 거리를 모두 구하고 그 중 가장 작은 값을 구한다. 구현하기 전에는 쉬워보였는데 1시간 32분 걸렸다.. 모든 집과 치킨 집의 좌표 찾기 houses = [] chickens = [] for i in range(N): for..
https://leetcode.com/problems/binary-tree-right-side-view/description/?envType=study-plan-v2&envId=top-interview-150 Binary Tree Right Side View - LeetCode Can you solve this real interview question? Binary Tree Right Side View - Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example 1: [h..
https://leetcode.com/problems/add-two-numbers/ 내 코드 # 11:15 ~ 11:58 (43") # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]: tmp_l1 = [] while l1.next: tmp_l1.append(str(l1.val)) l1 = l1.next tmp_l1.append(s..
https://www.acmicpc.net/problem/15685 15685번: 드래곤 커브 첫째 줄에 드래곤 커브의 개수 N(1 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에는 드래곤 커브의 정보가 주어진다. 드래곤 커브의 정보는 네 정수 x, y, d, g로 이루어져 있다. x와 y는 드래곤 커 www.acmicpc.net 아이디어 드래곤 커브 방향의 규칙성을 찾고 구현하여 풀었다. (1시간 40분 정도 걸렸다.....) 4 2 1 3 이라는 입력이 들어왔을 때를 예로 들면, g = 0 일 때, (4,2) 에서 1 방향으로 이동한다. g = 1 일 때, (4,1) 에서 2 방향으로 이동한다. g = 2 일 때, (3,1) 에서 3, 2 방향으로 이동한다. g = 3 일 때, (2,2) 에서..
lim.dev
'Coding Test/Python' 카테고리의 글 목록 (17 Page)