본문 바로가기

스택17

[leetcode 84] Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]. The largest rectangle is shown in the shaded area, which has area = 10 unit. 문제 풀이: 지난번에 풀었던 문제와 알고리즘이 동일하다. 또 못푼건 함정 ㅎㅎ.... eazymean.tistory.com/130 2020. 11. 8.
[leetcode 155] Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. getMin() -- Retrieve the minimum element in the stack. Example 1: Input ["MinStack","push","push","push","getMin","pop","top","getMin"] [[],[-2],[0],[-3],[],[],[],[]] Output [null,nu.. 2020. 11. 1.
[leetcode 85] Maximal Rectangle Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. 직사각형 최대 넓이 찾기 Example 1: Input: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] Output: 6 Explanation: The maximal rectangle is shown in the above picture. Example 2: Input: matrix = [] Output: 0 Example 3: Input: matrix.. 2020. 10. 28.
[leetcode 114] Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: 문제 풀이: - 순서가 root->left->right 순서: preorder임 - 스택을 사용해서 preorder 순회하기 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * Tr.. 2020. 10. 21.