Algorithm in LeetCode —— Stack

Stack Tips:

  • Parentheses matching and related problems. Problem 20, Problem 921, Problem 1021.
  • Basic stack pop and push operations. Problem 71, Problem 150, Problem 155, Problem 224, Problem 225, Problem 232, Problem 946, Problem 1047.
  • Encoding problems using a stack. Problem 394, Problem 682, Problem 856, Problem 880.
  • Monotonic stack. Use a stack to maintain an array of indices that is monotonically increasing or decreasing. Problem 84, Problem 456, Problem 496, Problem 503, Problem 739, Problem 901, Problem 907, Problem 1019.
TitleSolutionDifficultyTimeSpaceFavorite
20. Valid ParenthesesGoEasyO(log n)O(1)
42. Trapping Rain WaterGoHardO(n)O(1)❤️
71. Simplify PathGoMediumO(n)O(n)❤️
84. Largest Rectangle in HistogramGoMediumO(n)O(n)❤️
94. Binary Tree Inorder TraversalGoMediumO(n)O(1)
103. Binary Tree Zigzag Level Order TraversalGoMediumO(n)O(n)
144. Binary Tree Preorder TraversalGoMediumO(n)O(1)
145. Binary Tree Postorder TraversalGoHardO(n)O(1)
150. Evaluate Reverse Polish NotationGoMediumO(n)O(1)
155. Min StackGoEasyO(n)O(n)
173. Binary Search Tree IteratorGoMediumO(n)O(1)
224. Basic CalculatorGoHardO(n)O(n)
225. Implement Stack using QueuesGoEasyO(n)O(n)
232. Implement Queue using StacksGoEasyO(n)O(n)
331. Verify Preorder Serialization of a Binary TreeGoMediumO(n)O(1)
394. Decode StringGoMediumO(n)O(n)
402. Remove K DigitsGoMediumO(n)O(1)
456. 132 PatternGoMediumO(n)O(n)
496. Next Greater Element IGoEasyO(n)O(n)
503. Next Greater Element IIGoMediumO(n)O(n)
636. Exclusive Time of FunctionsGoMediumO(n)O(n)
682. Baseball GameGoEasyO(n)O(n)
726. Number of AtomsGoHardO(n)O(n)❤️
735. Asteroid CollisionGoMediumO(n)O(n)
739. Daily TemperaturesGoMediumO(n)O(n)
844. Backspace String CompareGoEasyO(n)O(n)
856. Score of ParenthesesGoMediumO(n)O(n)
880. Decoded String at IndexGoMediumO(n)O(n)
895. Maximum Frequency StackGoHardO(n)O(n)
901. Online Stock SpanGoMediumO(n)O(n)
907. Sum of Subarray MinimumsGoMediumO(n)O(n)❤️
921. Minimum Add to Make Parentheses ValidGoMediumO(n)O(n)
946. Validate Stack SequencesGoMediumO(n)O(n)
1003. Check If Word Is Valid After SubstitutionsGoMediumO(n)O(1)
1019. Next Greater Node In Linked ListGoMediumO(n)O(1)
1021. Remove Outermost ParenthesesGoMediumO(n)O(1)
1047. Remove All Adjacent Duplicates In StringGoMediumO(n)O(1)