본문 바로가기

0

(102)
207. Course Schedule 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 import collections class Solution: def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: indegrees = [0]*numCourses graph = defaultdict(list) for u, v in..
41. First Missing Positive leetcode.com/problems/first-missing-positive/ First Missing Positive - 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 class Solution: def firstMissingPositive(self, nums: List[int]) -> int: if 1 not in nums : return 1 n = len(nums) for i in range(n) : if nums[i] n : nums[i] = 1 fo..
988. Smallest String Starting From Leaf leetcode.com/problems/smallest-string-starting-from-leaf/ Smallest String Starting From Leaf - 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 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = l..
16. 3Sum Closest leetcode.com/problems/3sum-closest/ 3Sum Closest - 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 class Solution: def threeSumClosest(self, nums: List[int], target: int) -> int: diff = float('inf') n = len(nums) nums.sort() for i in range(n-2) : l, r = i+1, n-1 while l < r : curr ..
835. Image Overlap leetcode.com/problems/image-overlap/ Image Overlap - 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 class Solution: def largestOverlap(self, A: List[List[int]], B: List[List[int]]) -> int: posa = [] posb = [] for i in range(len(A)) : for j in range(len(A[0])) : if A[i][j] == 1 : p..
1305. All elements in two binary search trees leetcode.com/problems/all-elements-in-two-binary-search-trees/ All Elements in Two Binary Search Trees - 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 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # sel..
Union Find Find(x): get the identity of the group that the element x belongs to. Union(x, y): merge the two groups that the two elements belong to respectively. class DisjointSetUnion(object): def __init__(self, size) : self.parent = [i for i in range(size+1)] self.size = [1]*(size+1) def find(self, x): if self.parent[x] != x : self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self..
Mastering Design Patterns (1) Modules There is no first class support for namespaces. To create modules just attach an object to the global namespace. Westeros = {} This object is, by default, attached to the top-level object, so we need not do anything more than that. This allows you to spread your definitions over a number of files. Westeros = Westeros || {} Westeros.Castle = function(name) { this. name }; // constructor W..