목록BFS (9)
취미가 좋다
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ Lowest Common Ancestor of a Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution class Solution: def __init__(self): self.ans = None def lowestCommonAncestor(self, root, p, q) : ans = None def ..
https://www.acmicpc.net/problem/2636 2636번: 치즈 아래 과 같이 정사각형 칸들로 이루어진 사각형 모양의 판이 있고, 그 위에 얇은 치즈(회색으로 표시된 부분)가 놓여 있다. 판의 가장자리(에서 네모 칸에 X친 부분)에는 치즈가 놓 www.acmicpc.net Solution import sys input = sys.stdin.readline from collections import deque def melt(): num = 0 while(ready): i, j = ready.pop() cheese[i][j] = 0 num += 1 return num def chk(): while(q): i, j = q.pop() if cheese[i][j] == 1: ready.app..
https://leetcode.com/problems/kth-smallest-element-in-a-bst/ Kth Smallest Element in a BST - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution class Solution: def kthSmallest(self, root, k): def rank(node, ans): if node.left and rank(node.left, ans): return True ans.append(n..
https://leetcode.com/problems/invert-binary-tree/ Invert Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution from collections import deque class Solution: def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: if not root: return root d = deque() d..
https://www.acmicpc.net/problem/22868 22868번: 산책 (small) 첫 번째 줄에는 정점의 개수 $N$과 두 정점 사이를 잇는 도로의 개수 $M$이 공백으로 구분되어 주어진다. 두 번째 줄부터 $M + 1$ 번째 줄까지 정점 $A, B$가 공백으로 구분되어 주어진다. 정점 $A$와 www.acmicpc.net Solution from collections import defaultdict from queue import Queue import sys input = sys.stdin.readline n, m = map(int, input().split()) graph = defaultdict(list) for _ in range(m): a, b = map(int, inpu..
https://leetcode.com/problems/course-schedule-ii/ Course Schedule II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Solution class Solution: def __init__(self): self.ans = [] self.graph = defaultdict(set) self.visit = None def findOrder(self, numCourses: int, prerequisites: List..