随笔分类 -  stack

496. Next Greater Element I
摘要:https://www.youtube.com/watch?v=KZhjUwuMC0Y You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's ... 阅读全文

posted @ 2018-11-09 10:42 猪猪🐷

503. Next Greater Element II
摘要:Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first gr... 阅读全文

posted @ 2018-11-09 10:41 猪猪🐷

739. Daily Temperatures
摘要: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 whic... 阅读全文

posted @ 2018-11-09 10:36 猪猪🐷

456. 132 Pattern
摘要:Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i third的second值,其中的任何一个值都是大于当前的third值,如果有更大的值进来,那就等于形成了一个更优的second > third的这样一个组合,并且这时弹出的third值比以前... 阅读全文

posted @ 2018-11-09 10:20 猪猪🐷

150. Evaluate Reverse Polish Notation
摘要:变成符号在两个数前面,stack做 wyt211 发表于 2018-10-10 04:35 请问最后一题,可以把input reverse一下以后,按照lc的原题做法做嘛? 题有点不一样, 他是一个运算符后面可以跟多个数,数之间空格隔开, 运算符只有+, - 比如 * (+ 2 4 1) 3 =( 2 + 4 + 1 ) * 3. 1point3acres 我是用两个stack,一个存数字... 阅读全文

posted @ 2018-11-09 06:57 猪猪🐷

32. Longest Valid Parentheses
摘要:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. Example 1: Input: "(()" Output: 2 Explanation: The longest valid p... 阅读全文

posted @ 2018-11-08 02:31 猪猪🐷

331. Verify Preorder Serialization of a Binary Tree
摘要: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 #. ... 阅读全文

posted @ 2018-11-07 05:29 猪猪🐷

439. Ternary Expression Parser
摘要:Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is valid and only consists of digits 0-9, ?... 阅读全文

posted @ 2018-11-07 05:28 猪猪🐷

536. Construct Binary Tree from String
摘要:You need to construct a binary tree from a string consisting of parenthesis and integers. The whole input represents a binary tree. It contains an integer followed by zero, one or two pairs of parent... 阅读全文

posted @ 2018-11-07 05:28 猪猪🐷

726. Number of Atoms
摘要:Given a chemical formula (given as a string), return the count of each atom. An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name. 1... 阅读全文

posted @ 2018-11-06 11:56 猪猪🐷

85. Maximal Rectangle
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: Input: [ ["1","0","1","0","0"], ["1","0","1","1","1"], [" 阅读全文

posted @ 2018-11-06 11:52 猪猪🐷

224. Basic Calculator
摘要:Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty sp... 阅读全文

posted @ 2018-11-06 08:20 猪猪🐷

227. Basic Calculator II
摘要:http://www.cnblogs.com/grandyang/p/4601208.html Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators a... 阅读全文

posted @ 2018-11-06 08:19 猪猪🐷

772. Basic Calculator III
摘要:Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty sp... 阅读全文

posted @ 2018-11-06 08:18 猪猪🐷

844. Backspace String Compare
摘要:Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character. Example 1: Input: S = "ab#c", T = "ad#c" Output: true Explanation: Both... 阅读全文

posted @ 2018-09-20 18:31 猪猪🐷

84. Largest Rectangle in Histogram
摘要:84. Largest Rectangle in Histogram https://www.youtube.com/watch?v=KkJrGxuQtYo&t=129s https://leetcode.com/problems/largest-rectangle-in-histogram/solution/ https://www.cnblogs.com/boring09/p/42... 阅读全文

posted @ 2018-09-20 18:18 猪猪🐷

394. Decode String
摘要:394. Decode String Two solutions: solution 1 : Recursion , solution 2 : Iterative with stack to imitate the call stack used in recursion http://www.cnblogs.com/grandyang/p/5849037.html publ... 阅读全文

posted @ 2018-09-20 18:14 猪猪🐷

862. Shortest Subarray with Sum at Least K
摘要:If there is no non-empty subarray with sum at least K, return -1. Example 1: Input: A = [1], K = 1 Output: 1 Example 2: Input: A = [1,2], K = 4 Output 阅读全文

posted @ 2018-08-28 20:19 猪猪🐷

636. Exclusive Time of Functions
摘要:Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find the exclusive time of these functions. Each funct 阅读全文

posted @ 2018-08-28 20:14 猪猪🐷

20. Valid Parentheses
摘要:Three pairs {} [] () If we see {, we push } into the stack If we see [, we push ] into the stack If we see (, we push ) into the stack If we see curre 阅读全文

posted @ 2018-07-18 13:10 猪猪🐷

导航