일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Greedy
- dfs
- GenAI
- 생성형AI
- tree
- Stack
- GenerativeAI
- 슬라이딩윈도우
- 투포인터
- 파이썬
- 리트코드
- 릿코드
- 니트코드
- two-pointer
- stratascratch
- sql코테
- codeup
- graph
- nlp
- array
- heap
- BFS
- Python
- Python3
- 코드업
- 파이썬알고리즘
- LeetCode
- 알고리즘
- SQL
- binary Tree
- Today
- Total
목록array (11)
Tech for good

class Solution: def kClosest(self, points: List[List[int]], k: int) -> List[List[int]]: pq = [] for x, y in points: d = x * x + y * y pq.append((d, (x,y))) # make it a tuple heapify(pq) res = [] for i in range(k): res.append(heappop(pq)[1]) # heappop(pq) = (d, (x, y)) return res

class Solution: def lastStoneWeight(self, stones: List[int]) -> int: # what is heap? => find min/max using push() or pop() # it allows handling new value effeciently when we even insert new values. pq = [-x for x in stones] # pq = [-2, -7, -4, -1, -8, -1] heapify(pq) # heapify() -> make it into binarry tree for efficiency (only half-through traversa..

Properties 1The town judge trusts nobody.Properties 2Everybody (except for the town judge) trusts the town judge.Properties 3There is exactly one person that satisfies properties 1 and 2.class Solution: def findJudge(self, n: int, trust: List[List[int]]) -> int: # To figure out in-degree/out-degree using hash-map in_degree = defaultdict(int) out_degree = defaultdict(int)..

1. Linear Searchclass Solution: def search(self, nums: List[int], target: int) -> int: for i in range(len(nums)): if target == nums[i]: return i return -1Time Complexity: O(n)2. Binary SearchBinary Search, Tree -> Narrow down the scope w/ starter, end and middle!There are two ways for a Binary Search.1. Two pointer + while loop2. Recursion2.1. Two point..

https://leetcode.com/problems/jump-game/description/class Solution: def canJump(self, nums: List[int]) -> bool: max_reach = 0 for i in range(len(nums)): if i > max_reach: return False # Current index is unreachable max_reach = max(max_reach, i + nums[i]) # Update the farthest reachable index return True✅ Explanation:max_reach keeps t..

class Solution: def minSubsequence(self, nums: List[int]) -> List[int]: nums.sort(reverse=True) totalSum = sum(nums) result = [] current = 0 for num in nums: result.append(num) current += num if current > totalSum - current: break return resultclass Solution: def minSubsequence(self, nums: List[int]) ..

class Solution: def minMovesToSeat(self, seats: List[int], students: List[int]) -> int: students.sort(reverse=True) seats.sort(reverse=True) minMove = 0 for i in range(len(students)): minMove += abs(students[i] - seats[i]) return minMove✅ Why Use abs() (Absolute Value)?The problem asks for the total number of moves to align each student with a sea..

class Solution: def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int: # Sort boxTypes by units per box in descending order boxTypes.sort(key=lambda x: x[1], reverse=True) total_units = 0 for boxes, units_per_box in boxTypes: if truckSize == 0: break # Take as many boxes as possible, up to the truckSiz..

class Solution: def lemonadeChange(self, bills: List[int]) -> bool: five, ten = 0, 0 for bill in bills: if bill == 5: five += 1 elif bill == 10: if five == 0: return False five -= 1 ten += 1 else: if ten > 0 and five > 0: ten -= 1 ..

# Example 1students = [1,1,0,0], sandwiches = [0,1,0,1]students = [1,0,0,1], sandwiches = [0,1,0,1]students = [0,0,1,1], sandwiches = [0,1,0,1]students = [0,1,1], sandwiches = [1,0,1]students = [1,1,0], sandwiches = [1,0,1]students = [1,0], sandwiches = [0,1]students = [0,1], sandwiches = [0,1]students = [1], sandwiches = [1]students = [], sandwiches = []Output: 0# Example 2students = [1,1,1,0,0..