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

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..

# 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..

parentheses(괄호) 문제는 보통 stack 문제이다!class Solution: def maxDepth(self, s: str) -> int: depth = 0 max_depth = 0 for vp in s: if vp == '(': depth += 1 max_depth = max(max_depth, depth) elif vp == ')': depth -= 1 return max_depthExplanation:depth tracks the current level of nesting.max_de..

✅ Iterative in-order traversal using a stackclass Solution: def increasingBST(self, root: Optional[TreeNode]) -> Optional[TreeNode]: stack = [] dummy = TreeNode(-1) # Dummy node to build the result tree curr = dummy # Pointer to build the new tree node = root # Start traversal from the root while stack or node: # 1. Go ..

🌷 Stackpush(): 데이터를 넣는다/추가한다 (+) / Adds x to the top of the stackpop(): 데이터를 꺼낸다/뺀다 (-) / Removes and returns the top itemappend(): Add an element x to the end of a listclass Solution: def calPoints(self, operations: List[str]) -> int: stack = [] for op in operations: if op == "C": stack.pop() elif op == "D": stack.append(2 * ..

class Solution: def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: # Dictionary to store the next greater element for each number in nums2 next_greater = {} stack = [] # Traverse nums2 in order for num in nums2: # Maintain a decreasing stack; pop elements smaller than current num while stack and num > stack[-..

🌷 Subarray vs Subsequence"Do I need to pick connected elements?" - have to be contiguousSubarrayEx) arr = [1, 2, 3, 4]❌ [1, 3] is not valid — skips 2"Can I pick elements freely as long as I keep the order?"- do not have to be contiguousSubsequence✅ [1, 4] is valid — it's in the correct order. ✅ Code OverviewYou're implementing a sliding window approach, where:You track the maximum and minimum v..

🌷 Looking into Example -> Key is to return the furthest building indexExample 1:heights = [4, 2, 7, 6, 9, 14, 12], bricks = 5, ladders = 14 -> 2 (X)2 -> 7 (5) (Ladder)7 -> 6 (X)6 -> 9 (3) (Bricks 3)9 -> 14 (5) (Bricks 2; shortage of bricks)14 -> 12 (X)Thus, you can move by [4, 2, 7, 6, 9](Index) 0 1 2 3 4Example 2:heights = [4, 12, 2, 7, 3, 18, 20, 3, 19], bric..

class Solution: def frequencySort(self, s: str) -> str: # Step 1: Count frequency of each character freq = Counter(s) # Step 2: Build max-heap based on frequency # Use -count to simulate max-heap heap = [(-count, char) for char, count in freq.items()] heapq.heapify(heap) # Step 3: Build the result string from the heap result = []..

Example 1:gifts = [25, 64, 9, 4, 100], k = 4[25, 64, 9, 4, 100]-> (1회) [25, 64, 9, 4, 10]-> (2회) [25, 8, 9, 4, 10]-> (3회) [5, 8, 9, 4, 10]-> (4회) [5, 8, 9, 4, 3] (floor or the square root - floor: 내림)5 + 8 + 9 + 4 + 3 = 29 Follow these steps:Pick the largest pile of gifts.Replace it with the floor of its square root.Repeat this for k seconds.🔧 Best Tool for This?We need to efficiently get the l..