Stack
weixin_39145266
这个作者很懒,什么都没留下…
展开
-
946 Validate Stack Sequences
1 题目Given two sequencespushedandpoppedwith distinct values,returntrueif and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.Example 1:Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,...原创 2020-07-14 12:10:09 · 138 阅读 · 0 评论 -
42 Trapping Rain Water
1 题目Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented b...原创 2019-11-24 13:30:30 · 56 阅读 · 0 评论 -
921 Minimum Add to Make Parentheses Valid
1 题目Given a stringSof'('and')'parentheses, we add the minimum number of parentheses ('('or')', and in any positions ) so that the resulting parentheses string is valid.Formally, a parenth...原创 2019-08-11 19:55:40 · 65 阅读 · 0 评论 -
402 Remove K Digits
1 题目Given a non-negative integernumrepresented as a string, removekdigits from the number so that the new number is the smallest possible.Note:The length ofnumis less than 10002 and will b...原创 2019-08-06 20:43:56 · 74 阅读 · 0 评论 -
331 Verify Preorder Serialization of a Binary Tree
1 题目One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as#....原创 2019-07-04 21:37:16 · 51 阅读 · 0 评论 -
394 Decode String
1 题目Given an encoded string, return its decoded string.The encoding rule is:k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. Note thatki...原创 2019-07-09 22:25:38 · 57 阅读 · 0 评论 -
456 132 Pattern
1 题目Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, aksuch thati<j<kand ai< ak< aj. Design an algorithm that takes a list of n numbers as i...原创 2019-07-13 11:39:40 · 108 阅读 · 0 评论 -
341 Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Example 1:Input: [[1,1],2...原创 2019-07-07 18:05:08 · 92 阅读 · 0 评论 -
155 Min Stack
1 题目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()...原创 2019-05-07 15:25:23 · 147 阅读 · 0 评论 -
232 Implement Queue using Stacks
1 题目Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front elemen...原创 2019-05-06 17:46:21 · 63 阅读 · 0 评论 -
225 Implement Stack using Queues
1 题目Implement the following operations of a stack using queues.push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. empty() -- R...原创 2019-05-06 15:42:51 · 83 阅读 · 0 评论 -
71 Simplify Path
1 题目Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.In a UNIX-style file system, a period . refers to the current directory. Furth...原创 2019-04-15 14:05:35 · 65 阅读 · 0 评论 -
144 Binary Tree Preorder Traversal
1 题目Given a binary tree, return the preorder traversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,2,3]Follow up: Recursive solution is trivial, c...原创 2019-04-16 15:49:12 · 60 阅读 · 0 评论 -
103 Binary Tree Zigzag Level Order Traversal
1 题目Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given bin...原创 2019-04-12 12:53:51 · 70 阅读 · 0 评论 -
150 Evaluate Reverse Polish Notation
1 题目Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Note:Division between two in...原创 2019-04-15 17:13:46 · 51 阅读 · 0 评论 -
94 Binary Tree Inorder Traversal
1 题目Given a binary tree, return theinordertraversal of its nodes' values.2 尝试解class Solution {public: vector<int> inorderTraversal(TreeNode* root) { vector<int> resul...原创 2019-03-29 09:19:02 · 54 阅读 · 0 评论