스택11 [코딩 + 알고리즘 완주반] 12일차. 스택, 링크드 리스트 # 스택(Stack) 데이터를 제한적으로 접근할 수 있는 구조 - 한쪽 끝에서만 자료를 넣거나 뺄 수 있는 구조 가장 나중에 쌓은 데이터를 가장 먼저 빼낼 수 있는 구조 LIFO(Last In First Out) # 스택의 활용 컴퓨터 내부의 프로세스 구조의 함수 동작 방식 # 주요 기능 -push() : 데이터를 스택에 넣기 -pop() : 데이터를 스택에서 꺼내기 # 스택 구조 프로세스 실행 구조를 스택과 비교해서 이해 # 스택의 장단점 장점 : 구조가 단순해서 구현이 쉽다 더이터 저장/읽기 속도 빠르다 단점 : -데이터 최대 개수를 미리 정해야한다. 저장공간의 낭비가 발생할 수 있음 # 리스트 변수로 스택 구현해보기 stack_list = list() def push(data): stack_list.. 2021. 3. 27. [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] 316. Remove Duplicate Letters # Problem Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Note: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/ Constraints: 1 str: counter, seen, stack = collections.Counter(s), set(), [] for.. 2021. 3. 23. [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. 이전 1 2 다음 반응형