본문 바로가기

파이썬 알고리즘 인터뷰10

❗️[LEET CODE] 310. Minimum Height Trees # Problem A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edges[i] = [ai, bi] indicates that there is an undirected edge between the two nodes ai and bi in the tree, you can choose any node of the tree .. 2021. 4. 20.
[LEET CODE] 739. Daily Temperatures # Problem Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead. For example, given the list of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0]. Note: The length of temp.. 2021. 3. 29.
[LEET CODE] 622. Design Circular Queue # Problem Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called "Ring Buffer". One of the benefits of the circular queue is that we can make use of the spaces in front of the .. 2021. 3. 29.
[LEET CODE] 232. Implement Queue using Stacks # Problem Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: void push(int x) Pushes element x to the back of the queue. int pop() Removes the element from the front of the queue and returns it. int peek() Returns the element at the front of the queu.. 2021. 3. 26.
[LEET CODE] 225. Implement Stack using Queues # Problem Implement a last in first out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal queue (push, top, pop, and empty). Implement the MyStack class: void push(int x) Pushes element x to the top of the stack. int pop() Removes the element on the top of the stack and returns it. int top() Returns the element on the top of the stack. boolean.. 2021. 3. 26.
[LEET CODE] 20. Valid Parentheses # Problem Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Constraints: 1 bool: stack = [] table = { ')': '(', '}': '{', ']': '[', } # 스택 이용 예외 처리 및 일치 여부 판별 for char in s: if char not in.. 2021. 3. 23.
반응형