| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- SQL
- 파이썬
- dfs
- heap
- 알고리즘
- array
- GenerativeAI
- 니트코드
- 코드업
- 생성형AI
- binary Tree
- nlp
- BFS
- Greedy
- codeup
- 파이썬알고리즘
- stratascratch
- Stack
- 리트코드
- 슬라이딩윈도우
- GenAI
- LeetCode
- 릿코드
- graph
- sql코테
- two-pointer
- 투포인터
- tree
- Python
- Python3
- Today
- Total
목록Stack (9)
Tech for good
https://neetcode.io/problems/daily-temperatures?list=neetcode150 NeetCode neetcode.ioApproach 1 -> nest loop (time complexity: O(n^2)) class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: res = [] # t = temperature[i] for i, t in enumerate(temperatures): j = i+1 while j = temperatures[j]: j+=1 ..
https://neetcode.io/problems/minimum-stack?list=neetcode150 NeetCode neetcode.ioclass MinStack: def __init__(self): self.stack = [] self.min_stack = [] def push(self, val: int) -> None: self.stack.append(val) if self.min_stack: min_stack_element = self.min_stack[-1] self.min_stack.append(min(val, min_stack_element)) else: ..
https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/ class Solution: def removeDuplicates(self, s: str) -> str: stack = [] for c in s: if stack and stack[-1] == c: stack.pop() else: stack.append(c) return ''.join(stack)
# 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 ..
🌷 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[-..