본문 바로가기
반응형

분류 전체보기128

[DSA][Stack] 03. Evaluate Reverse Polish Notation LeetCode 150 03. Evaluate Reverse Polish NotationYou are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.Evaluate the expression. Return an integer that represents the value of the expression.Note that:• The valid operators are '+', '-', '*', and '/'.• Each operand may be an integer or another expression.• The division between two integers a.. 2025. 5. 27.
[DSA][Stack] 02. Min Stack LeetCode 155 02. Min StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement the MinStack class:• MinStack() initializes the stack object.• void push(int val) pushes the element val onto the stack.• void pop() removes the element on the top of the stack.• int top() gets the top element of the stack.• int getMin() retrieves the minimum eleme.. 2025. 5. 26.
[DSA][Stack] 01. Valid Parentheses LeetCode 20 01. Valid ParenthesesGiven a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:1. Open brackets must be closed by the same type of brackets.2. Open brackets must be closed in the correct order.3. Every close bracket has a corresponding open bracket of the same type. [질문하기]- 문자열에 공백 등 다른 문자열이 포함될.. 2025. 5. 25.
[DSA][Array & Hashing] 08. Longest Consecutive Sequence LeetCode 128 08. Longest Consecutive SequenceGiven an unsorted array of integers nums, return the length of the longest consecutive elements sequence.You must write an algorithm that runs in O(n) time. [질문하기]- 음수가 포함될 수 있나요? YES- 정수 배열에 중복된 값이 존재할 수 있나요? YES [아이디어]연속된 숫자를 판단할 때, num을 기준으로 num + 1이 있는지 확인하자. 그러기 위해 탐색에 유리한 자료구조인 set을 사용하자. [풀이 1] Setclass Solution: def longestConsecutive(se.. 2025. 5. 22.