목록알고리즘 문제풀이/Leetcode (22)
취미가 좋다
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://leetcode.com/problems/maximal-square/ Maximal Square - 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 maximalSquare(self, matrix): ROW, COL = len(matrix), len(matrix[0]) ans = 0 for i in range(COL): matrix[0][i] = 1 if matrix[0][i]=='1' else 0 ..
https://leetcode.com/problems/kth-largest-element-in-an-array/ Kth Largest Element in an Array - 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 import random class Solution: def findKthLargest(self, nums, k): k = len(nums) - k return self.quick(nums, k) def quick(self, nu..
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..
https://leetcode.com/problems/implement-trie-prefix-tree/ Implement Trie (Prefix 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 Trie: def __init__(self): self.dic = {} def insert(self, word): temp = self.dic for c in word: if not temp.get(c): temp[c] = {} te..
https://leetcode.com/problems/course-schedule/ Course Schedule - 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 queue import Queue class Solution: def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: q = Queue() a2b = {} # a : 조건이 필요한 수업 b2a ..