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

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

Look through Example g = child A want 1 number of cookie, child B want 2 number of cookies, child C want 3 number of cookiess = cookie A is 1 number of cookie, cookie B is 2 number of cookiesclass Solution: def findContentChildren(self, g: List[int], s: List[int]) -> int: g.sort() s.sort() child = 0 # pointer to children cookie = 0 # pointer to cookies whi..

class Solution: def arrayPairSum(self, nums: List[int]) -> int: nums.sort() return sum(nums[::2])🧠 Greedy Strategy:To maximize the sum of the minimums of all n pairs, you should:Sort the arrayAlways pair adjacent elements: (nums[0], nums[1]), (nums[2], nums[3]), ...This ensures that the smaller number in each pair is as large as possible — which directly contributes to the fina..

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

💡 Key Idea (using stack):Use a stack (LIFO) to store the values of the nodes. Then, go through the list again and compare each node’s value with the value popped from the stack. If all match, it's a palindrome.# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclass Solution: def isPalindrome(self,..

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