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

class Solution: def largestOddNumber(self, num: str) -> str: for i in range(len(num)-1, -1, -1): if int(num[i]) % 2 == 1: return ''.join(num[:i+1]) return "" # 64278# i = 3# num = [6, 4, 2, 7, 8]# num[:i] -> [6, 4, 2]# num[:i+1] -> [6, 4, 2, 7] Backward iteration in Pythonrange function is provided with three arguments(N, -1, -1). Use th..

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 maximum69Number (self, num: int) -> int: num_str = list(str(num)) for i in range(len(num_str)): if num_str[i] == '6': num_str[i] = '9' break # Only change the single element return int(''.join(num_str))

class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort(reverse=True) # Sort descending for greedy check for i in range(len(nums)-2): a, b, c = nums[i], nums[i+1], nums[i+2] if b + c > a: # Triangle inequality return a + b + c return 0 for i in range(len(nums) - 2):is used because we are checking triplets of side ..

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 문제이다!1. Stackclass Solution: def maxDepth(self, s: str) -> int: stack = [] max_depth = 0 for char in s: if char == '(': stack.append('(') max_depth = max(max_depth, len(stack)) elif char == ')': if stack: stack.pop() return max_depth💡 Key Idea:Every t..

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