Stack
文章平均质量分 72
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Reverse Nodes in Even Length Groups
You are given theheadof a linked list.The nodes in the linked list aresequentiallyassigned tonon-emptygroups whose lengths form the sequence of the natural numbers (1, 2, 3, 4, ...). Thelengthof a group is the number of nodes assigned to it. In o...原创 2021-11-14 14:50:07 · 307 阅读 · 0 评论 -
Basic Calculator 总结
Basic CalculatorBasic Calculator IIBasic Calculator III三个题目可以用一种解法;原创 2020-07-17 11:45:52 · 843 阅读 · 0 评论 -
Brace Expansion
A stringSrepresents a list of words.Each letter in the word has 1 or more options. If there is one option, the letter is represented as is. If there is more than one option, then curly braces de...原创 2020-01-16 11:53:58 · 327 阅读 · 0 评论 -
Asteroid Collision
We are given an arrayasteroidsof integers representing asteroids in a row.For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same ..原创 2020-06-20 03:53:15 · 198 阅读 · 0 评论 -
Print Immutable Linked List in Reverse
You are given an immutable linked list, print out all values of each node in reverse with the help of the followinginterface:ImmutableListNode:An interface of immutable linked list, you are given the head of the list.You need to use the following func..原创 2020-06-08 10:38:41 · 267 阅读 · 0 评论 -
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 parenthesis. The integer represents the root's value and a pai原创 2020-06-08 05:25:23 · 197 阅读 · 0 评论 -
Remove All Adjacent Duplicates in String II
Given a strings, akduplicate removalconsists of choosingkadjacent and equal letters fromsand removingthem causing the left and the right side of the deleted substring to concatenate together.We repeatedly makekduplicate removals onsuntil we ...原创 2020-06-03 13:24:28 · 149 阅读 · 0 评论 -
Exclusive Time of Functions
On asingle threadedCPU, we execute some functions. Each function has a unique id between0andN-1.We store logs in timestamp order that describe when a function is entered or exited.Each log is a string with this format:"{function_id}:{"start" | "...原创 2020-05-27 13:06:06 · 287 阅读 · 0 评论 -
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 greater number to its traversing-order next in the array, w原创 2020-05-25 05:41:38 · 195 阅读 · 0 评论 -
Valid Parenthesis String
Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these rules:Any left parenthesis'('must have a corresponding right parenthesis')'...原创 2020-05-22 13:38:03 · 276 阅读 · 0 评论 -
Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key. The ...原创 2014-01-17 13:18:43 · 633 阅读 · 0 评论 -
Add Two Numbers II
You are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-10-29 09:44:13 · 383 阅读 · 0 评论 -
Longest Valid Parentheses
Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", wh原创 2014-12-02 15:23:30 · 655 阅读 · 0 评论 -
Minimum Add to Make Parentheses Valid
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 parentheses string is valid if and only if:It is the empty string, ...原创 2020-05-12 13:00:43 · 179 阅读 · 0 评论 -
Remove Duplicate Letters && Smallest Subsequence of Distinct Characters
Given a string which contains only lowercase letters, 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.Example 1:Input: "bcabc"原创 2020-05-11 13:55:19 · 168 阅读 · 0 评论 -
Next Greater Element I
You are given two arrays(without duplicates)nums1andnums2wherenums1’s elements are subset ofnums2. Find all the next greater numbers fornums1's elements in the corresponding places ofnums2.The Next Greater Number of a numberxinnums1is the fi...原创 2020-05-11 01:11:45 · 275 阅读 · 0 评论 -
Remove All Adjacent Duplicates In String
Given a stringSof lowercase letters, aduplicate removalconsists of choosing two adjacent and equal letters, and removingthem.We repeatedly make duplicate removals on S until we no longer can.Return the final string after all such duplicate removal...原创 2020-05-10 02:56:17 · 273 阅读 · 0 评论 -
Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
Given anarray of integersnumsand anintegerlimit, return the size of the longest continuous subarray such that the absolute difference between any two elements is less than or equal tolimit.In ...原创 2020-05-04 00:38:24 · 403 阅读 · 0 评论 -
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-negativeintegers and empty sp...原创 2020-04-30 13:34:13 · 471 阅读 · 0 评论 -
N-ary Tree Postorder Traversal
Given an n-ary tree, return thepostordertraversal of its nodes' values.Nary-Tree input serializationis represented in their level order traversal, each group of children is separated by the null ...原创 2020-04-26 13:08:58 · 225 阅读 · 0 评论 -
N-ary Tree Preorder Traversal
Given an n-ary tree, return thepreordertraversal of its nodes' values.Nary-Tree input serializationis represented in their level order traversal, each group of children is separated by the null v...原创 2020-04-26 12:38:57 · 190 阅读 · 0 评论 -
Daily Temperatures
Given a list of daily temperaturesT, 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 which...原创 2020-04-25 05:10:52 · 288 阅读 · 0 评论 -
Validate Stack Sequences
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:...原创 2020-03-17 10:19:13 · 332 阅读 · 0 评论 -
Minimum Cost Tree From Leaf Values
Given an arrayarrof positive integers, consider all binary trees such that:Each node has either 0 or 2 children; The values ofarrcorrespond to the values of eachleafin an in-order traversal o...原创 2020-03-16 04:45:26 · 310 阅读 · 0 评论 -
Minimum Remove to Make Valid Parentheses
Given a stringsof'(',')'and lowercase English characters.Your task is to remove the minimum number of parentheses ('('or')',in any positions ) so that the resultingparentheses stringis ...原创 2020-03-08 13:22:18 · 409 阅读 · 0 评论 -
Two Sum BSTs
Given two binary search trees, returnTrueif and only if there is a node in the first tree and a node in the second tree whose valuessum up to a given integertarget.Example 1:正在上传…重新上传取消...原创 2020-03-02 13:07:01 · 346 阅读 · 0 评论 -
Convert Binary Search Tree to Sorted Doubly Linked List
Example 1:Input: root = [4,2,5,1,3]Output: [1,2,3,4,5]思路:Inorder traverse,用stack做;记录一下first 和last node就可以了;最后返回dummpy.right;/*// Definition for a Node.class Node { public int val; ...原创 2020-03-02 08:23:09 · 200 阅读 · 0 评论 -
Sliding Window Maximum
Given an arraynums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers in the window. Each time the sliding window...原创 2016-09-06 12:23:56 · 340 阅读 · 0 评论 -
Closest Binary Search Tree Value II
Given a non-empty binary search tree and a target value, findkvalues in the BST that are closest to the target.ExampleExample 1:Input:{1}0.0000001Output:[1]Explanation:Binary tree {1},...原创 2016-10-03 06:00:49 · 491 阅读 · 0 评论 -
单调栈类型总结
Largest Rectangle in Histogram给出的n个非负整数表示每个直方图的高度,每个直方图的宽均为1,在直方图中找到最大的矩形面积。Example样例 1:输入:[2,1,5,6,2,3]输出:10解释:第三个和第四个直方图截取矩形面积为2*5=10。思路:求最大矩阵,就是求每个元素height * 最左边第一个小于他的元素 到右边第一个小于他的...原创 2020-01-12 15:40:41 · 656 阅读 · 0 评论 -
Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solution is trivial...原创 2014-01-17 12:28:20 · 1017 阅读 · 0 评论 -
Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() ...原创 2015-01-11 13:03:24 · 605 阅读 · 0 评论 -
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:Given the list...原创 2016-09-08 14:36:19 · 700 阅读 · 0 评论 -
Flatten List
Given a list, each element in the list can be a list or integer. flatten it into a simply list with integers.ExampleExample 1: Input: [[1,1],2,[1,1]] Output: [1,1,2,1,1] Explanation: flatt...原创 2019-12-15 08:04:01 · 158 阅读 · 0 评论 -
Max Tree
Given an integer array with no duplicates. A max tree building on this array is defined as follow:The root is the maximum number in the array The left subtree and right subtree are the max trees of...原创 2019-12-01 03:59:35 · 336 阅读 · 0 评论 -
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.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0...原创 2014-12-16 09:04:00 · 536 阅读 · 0 评论 -
Trapping Rain water
Givennnon-negative integers representing an elevation map where the width of each bar is1, compute how much water it is able to trap after raining.ExampleExample 1:Input: [0,1,0]Output: 0...原创 2016-09-14 11:29:38 · 477 阅读 · 0 评论 -
Inorder Predecessor in BST
Given a binary search tree and a node in it, find the in-order predecessor of that node in the BST.ExampleExample1Input: root = {2,1,3}, p = 1Output: nullExample2Input: root = {2,1}, p =...原创 2019-11-19 12:57:13 · 443 阅读 · 0 评论 -
Longest Absolute File Path
Suppose we abstract our file system by a string in the following manner:The string"dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext"represents:dir subdir1 subdir2 file.extThe direc原创 2016-09-20 11:39:23 · 452 阅读 · 0 评论 -
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-negativeintegers and em原创 2020-04-30 10:57:18 · 347 阅读 · 0 评论