题库chevron_right分类chevron_right
layers

140 道题目
简单: 23中等: 75困难: 42

栈 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
20

有效的括号

Determine if a string of parentheses, brackets, and braces is correctly nested using a stack for proper order validation…

简单
32

最长有效括号

Compute the length of the longest well-formed parentheses substring using state transition dynamic programming and stack…

困难
42

接雨水

Calculate the total trapped rain water using the elevation map array, leveraging dynamic programming and two-pointer pat…

困难
71

简化路径

Simplify a Unix-style path by transforming it into its canonical form using stack-based state management.

中等
84

柱状图中最大的矩形

Find the maximal rectangular area in a histogram using stack-based state management for precise bar tracking and width c…

困难
85

最大矩形

Compute the largest rectangle of 1's in a binary matrix using dynamic programming and stack-based state transitions effi…

困难
94

二叉树的中序遍历

Binary Tree Inorder Traversal asks you to visit left subtree, node, then right subtree without losing position while mov…

简单
114

二叉树展开为链表

Flatten a binary tree into a right-skewed linked list by manipulating pointers following a pre-order traversal, handling…

中等
143

重排链表

Reorder List requires careful pointer manipulation in a singly linked list to interleave nodes from the ends without alt…

中等
144

二叉树的前序遍历

Perform a binary tree preorder traversal by visiting root nodes first, then left and right subtrees, tracking state iter…

简单
145

二叉树的后序遍历

Solve Binary Tree Postorder Traversal using state tracking and binary-tree traversal techniques, focusing on Stack, Tree…

简单
150

逆波兰表达式求值

Compute the result of an arithmetic expression in Reverse Polish Notation using a stack to manage operands efficiently.

中等
155

最小栈

Design a stack with O(1) operations to push, pop, retrieve the top element, and get the minimum element in constant time…

中等
173

二叉搜索树迭代器

Implement an iterator for in-order traversal of a binary search tree (BST), maintaining traversal state with stack-based…

中等
224

基本计算器

Implement a basic calculator to evaluate mathematical expressions, ensuring correct evaluation with stack-based manageme…

困难
225

用队列实现栈

This problem tests your ability to simulate a LIFO stack using two queues while preserving all standard stack operations…

简单
227

基本计算器 II

Basic Calculator II evaluates a mathematical expression with operators and integers, handling basic arithmetic with prec…

中等
232

用栈实现队列

Implement a queue using two stacks, focusing on stack-based state management to achieve FIFO behavior in a queue.

简单
234

回文链表

Solve Palindrome Linked List by finding the midpoint, reversing the second half, and comparing mirrored nodes in linear …

简单
316

去除重复字母

Remove duplicate letters from a string to produce the lexicographically smallest result using stack-based state manageme…

中等
321

拼接最大数

Create Maximum Number involves merging digits from two arrays while preserving order, maximizing the resulting number.

困难
331

验证二叉树的前序序列化

Determine if a given string correctly represents a binary tree preorder traversal using state tracking and slot counting…

中等
341

扁平化嵌套列表迭代器

Implement an iterator to flatten a nested list of integers, accounting for potential nesting levels.

中等
385

迷你语法分析器

Deserialize a nested list string using stack-based state management, handling integers and nested lists with depth-first…

中等
388

文件的最长绝对路径

Find the length of the longest absolute file path in a filesystem string using stack-based depth tracking efficiently.

中等
394

字符串解码

Decode a nested encoded string using stack-based state management, handling repeated patterns efficiently with recursion…

中等
402

移掉 K 位数字

Remove K Digits requires selecting which digits to drop using a monotonic stack for the smallest possible integer result…

中等
445

两数相加 II

Add Two Numbers II involves summing two numbers represented as linked lists and returning the result as a new linked lis…

中等
456

132 模式

Identify whether a given integer array contains a 132 pattern subsequence using efficient stack and search techniques.

中等
488

祖玛游戏

The Zuma Game involves clearing balls from the board using a limited hand, applying dynamic programming and state transi…

困难
496

下一个更大元素 I

Find the next greater element for each number in nums1 from the nums2 array using an optimized approach.

简单
503

下一个更大元素 II

Solve the Next Greater Element II problem by using a stack-based state management approach for circular arrays.

中等
581

最短无序连续子数组

Find the shortest unsorted continuous subarray that, if sorted, would sort the entire array.

中等
589

N 叉树的前序遍历

Solve the N-ary Tree Preorder Traversal problem using depth-first search and stack-based traversal methods.

简单
590

N 叉树的后序遍历

Postorder traversal of an N-ary tree can be efficiently solved using DFS and stack-based methods, tracking state across …

简单
591

标签验证器

The Tag Validator problem involves validating a code snippet by parsing through tags using a stack-based state managemen…

困难
636

函数的独占时间

Solve the 'Exclusive Time of Functions' problem using stack-based state management for accurate function execution time …

中等
654

最大二叉树

Construct a maximum binary tree by recursively selecting the largest element and dividing the array into left and right …

中等
678

有效的括号字符串

Solve the Valid Parenthesis String problem by leveraging state transition dynamic programming to handle parentheses and …

中等
682

棒球比赛

Simulate baseball score operations using a stack-based approach to compute the final score after all operations.

简单
726

原子的数量

Compute the exact count of each atom in a chemical formula using stack-based state management and hashing techniques eff…

困难
735

小行星碰撞

Determine the final positions of moving asteroids using a stack-based simulation for efficient collision resolution in l…

中等
736

Lisp 语法解析

Parse Lisp expressions using stack-based state management to evaluate variables and operations.

困难
739

每日温度

In the Daily Temperatures problem, you need to find out how many days to wait for a warmer temperature based on given da…

中等
768

最多能完成排序的块 II

Determine the maximum number of chunks you can split an array into so that sorting each chunk results in a fully sorted …

困难
769

最多能完成排序的块

The Max Chunks To Make Sorted problem requires you to split an array into the maximum number of chunks that can be sorte…

中等
770

基本计算器 IV

Simplify mathematical expressions using stack-based state management, handling variables, operators, and polynomial term…

困难
844

比较含退格的字符串

Compare two strings after processing backspaces using efficient two-pointer scanning and careful invariant tracking to e…

简单
853

车队

The Car Fleet problem asks how many car fleets will reach a target given their starting positions and speeds, considerin…

中等
856

括号的分数

Calculate the score of a balanced parentheses string using stack-based state management for an optimal solution.

中等
880

索引处的解码字符串

Decode the string and find the k-th letter efficiently using stack-based state management in this problem.

中等
895

最大频率栈

Design a stack-like data structure to manage elements and handle frequent stack operations, including popping the most f…

困难
897

递增顺序搜索树

Rearrange a binary search tree so all nodes follow increasing order with only right children using in-order traversal.

简单
901

股票价格跨度

Design an efficient algorithm using stacks to calculate the stock span for daily price quotes.

中等
907

子数组的最小值之和

Calculate the sum of minimum values across all subarrays of a given array modulo 10^9 + 7.

中等
921

使括号有效的最少添加

Compute the minimum insertions needed to make a parentheses string valid using efficient stack-based state tracking tech…

中等
936

戳印序列

Solve Stamping The Sequence with stack-based state management to convert string s to target using stamp efficiently.

困难
946

验证栈序列

Determine if a sequence of push and pop operations can produce the given popped array using a stack-based state approach…

中等
962

最大宽度坡

Find the maximum width of a ramp where nums[i] <= nums[j] for i < j using a two-pointer approach.

中等
975

奇偶跳

Determine the number of valid starting indices in an array where you can reach the end with alternating odd and even jum…

困难
1003

检查替换后的词是否有效

Determine if a string can be built from repeated 'abc' insertions using stack-based state management, verifying sequence…

中等
1006

笨阶乘

Compute the clumsy factorial of a number using a fixed rotation of multiply, divide, add, and subtract operations effici…

中等
1008

前序遍历构造二叉搜索树

Construct a binary search tree directly from a preorder traversal array using stack-based state tracking efficiently.

中等
1019

链表中的下一个更大节点

Find the next greater value for each node in a linked list using monotonic stack techniques for efficient traversal.

中等
1021

删除最外层的括号

Remove Outermost Parentheses simplifies a valid parentheses string by removing the outermost layers of parentheses in ea…

简单
1047

删除字符串中的所有相邻重复项

Solve Remove All Adjacent Duplicates In String by simulating deletions with a stack that collapses matching neighbors im…

简单
1081

不同字符的最小子序列

The Smallest Subsequence of Distinct Characters problem asks you to find the lexicographically smallest subsequence of a…

中等
1096

花括号展开 II

Solve Brace Expansion II efficiently by using stack-based state management to generate all unique combinations of nested…

困难
1106

解析布尔表达式

Solve the "Parsing A Boolean Expression" problem by evaluating boolean expressions using stack-based state management, r…

困难
1111

有效括号的嵌套深度

This problem challenges you to compute the maximum nesting depth of two valid parentheses strings using stack-based stat…

中等
1124

表现良好的最长时间段

The Longest Well-Performing Interval problem challenges you to find the longest subarray where tiring days exceed non-ti…

中等
1130

叶值的最小代价生成树

Compute the minimum sum of non-leaf nodes in a binary tree formed from array leaves using dynamic programming efficientl…

中等
1172

餐盘栈

Design a system that manages dinner plate stacks using stack-based state management, handling dynamic plate placement an…

困难
1190

反转每对括号间的子串

Reverse all substrings within matched parentheses using a stack-based approach for efficient state tracking and reversal…

中等
1209

删除字符串中的所有相邻重复项 II

Remove all adjacent duplicates in the string using stack-based state management with a given threshold k.

中等
1249

移除无效的括号

Given a string with parentheses and letters, remove the fewest parentheses to produce any valid balanced string efficien…

中等
1381

设计一个支持增量操作的栈

Implement a stack that supports push, pop, and targeted increment operations efficiently using array-based state managem…

中等
1441

用栈操作构建数组

Simulate stack operations to match a target array while processing numbers from 1 to n.

中等
1472

设计浏览器历史记录

Implement a browser history tracker with back, forward, and visit operations using linked-list pointer manipulation effi…

中等
1475

商品折扣后的最终价格

Calculate final prices with discounts applied in a shop using a stack-based state management approach to find the correc…

简单
1504

统计全 1 子矩形

Count Submatrices With All Ones is a dynamic programming problem focusing on submatrix counting using an efficient row-b…

中等
1526

形成目标数组的子数组最少增加次数

The problem asks for the minimum number of operations to transform an initial array of zeros into a target array using s…

困难
1541

平衡括号字符串的最少插入次数

Compute the minimum insertions to transform a parentheses string into a balanced string using efficient stack tracking.

中等
1544

整理字符串

This problem requires removing adjacent characters that cancel each other out, leveraging stack-based state management.

简单
1574

删除最短的子数组使剩余数组有序

Find the shortest subarray to remove in order to make an array non-decreasing using binary search and two-pointer techni…

中等
1598

文件夹操作日志搜集器

Simulate folder navigation based on a list of operations to determine the current folder depth.

简单
1614

括号的最大嵌套深度

Find the maximum nesting depth of parentheses in a valid string using stack-based state management.

简单
1653

使字符串平衡的最少删除次数

Determine the minimum number of deletions to transform a string of 'a' and 'b' into a balanced order using DP.

中等
1673

找出最具竞争力的子序列

Identify the lexicographically smallest subsequence of size k using stack-based greedy selection in array traversal.

中等
1700

无法吃午餐的学生数量

Simulate a queue of students with sandwich preferences and determine how many can't eat based on available sandwiches.

简单
1717

删除子字符串的最大得分

Compute the highest score by greedily removing specific substrings using a stack to track state transitions efficiently.

中等
1776

车队 II

Car Fleet II involves calculating collision times between cars traveling at different speeds along a one-lane road using…

困难
1793

好子数组的最大分数

Maximize the score of a good subarray using binary search to explore the valid answer space with a focus on two-pointer …

困难
1856

子数组最小乘积的最大值

The problem asks to find the maximum min-product of any non-empty subarray of nums.

中等
1896

反转表达式值的最少操作次数

Determine the minimum operations to change a boolean expression's result using state transition dynamic programming effi…

困难
1910

删除一个字符串中所有出现的给定子字符串

Remove all occurrences of a specified substring from a string using efficient stack-based state management.

中等
1944

队列中可以看到的人数

Compute how many people each person in a queue can see to their right using efficient stack-based state management.

困难
1963

使字符串平衡的最小交换次数

Determine the minimum swaps to balance a bracket string using two-pointer scanning with invariant tracking efficiently.

中等
1996

游戏中弱角色的数量

Identify all weak characters in a game by analyzing attack and defense values using a stack-based greedy sorting approac…

中等
2000

反转单词前缀

Reverse the prefix of a string starting from index 0 to the first occurrence of a given character.

简单
2019

解出数学表达式的学生分数

Calculate student scores for a single-digit math expression using state transition dynamic programming to track all vali…

困难
2030

含特定字母的最小子序列

Find the lexicographically smallest subsequence of length k with at least repetition occurrences of a given letter using…

困难
2104

子数组范围和

Compute the total sum of ranges for all contiguous subarrays efficiently using stack-based state management techniques.

中等
2116

判断一个括号字符串是否有效

Determine if a parentheses string can be transformed into a valid sequence considering locked positions using stack logi…

中等
2130

链表最大孪生和

Find the maximum twin sum in a linked list by manipulating pointers efficiently and leveraging stack or reversal techniq…

中等
2197

替换数组中的非互质数

Replace Non-Coprime Numbers in Array uses stack-based state management to iteratively merge adjacent non-coprime integer…

困难
2211

统计道路上的碰撞次数

Count Collisions on a Road is a problem where you calculate the number of car collisions based on their movements in a s…

中等
2216

美化数组的最少删除数

Determine the minimum deletions required to transform an array into a beautiful sequence using stack-based state managem…

中等
2281

巫师的总力量和

The Sum of Total Strength of Wizards problem asks for the sum of the total strengths of all contiguous subarrays of wiza…

困难
2289

使数组按非递减顺序排列

Determine the minimum steps to make an array non-decreasing using linked-list pointer manipulation and monotonic stack t…

中等
2296

设计一个文本编辑器

Design a text editor that supports text manipulation and cursor navigation operations efficiently with linked-list-based…

困难
2334

元素值大于变化阈值的子数组

Find the size of a subarray with all elements greater than threshold divided by length using stack-based state managemen…

困难
2375

根据模式串构造最小数字

Construct the lexicographically smallest string that fits the increasing and decreasing conditions of a given pattern.

中等
2390

从字符串中移除星号

Remove all stars from a string by simulating the removal process using a stack to manage characters and stars efficientl…

中等
2434

使用机器人打印字典序最小的字符串

Solve the problem of using a robot to print the lexicographically smallest string with stack-based state management.

中等
2454

下一个更大元素 IV

Find the second greater integer for each element in an array using binary search and monotonic stack techniques.

困难
2487

从链表中移除节点

This problem requires removing nodes from a linked list when a larger node exists to their right, testing pointer manipu…

中等
2589

完成所有任务的最少时间

Determine the minimum active time for a computer to complete all scheduled tasks within their specific time windows effi…

困难
2617

网格图中最少访问的格子数

Determine the minimum number of cells to visit in a grid using state transition dynamic programming and efficient traver…

困难
2645

构造有效字符串的最少插入数

Determine the minimum insertions required to transform a given string into repeated concatenations of 'abc' using dynami…

中等
2696

删除子串后的字符串最小长度

Determine the smallest string length after repeatedly removing AB or CD substrings using stack-based simulation techniqu…

简单
2736

最大和查询

Find the maximum sum of paired elements from two arrays under query constraints using efficient binary search techniques…

困难
2751

机器人碰撞

Robot Collisions involves simulating robot movements and handling collisions with stack-based state management.

困难
2813

子序列最大优雅度

Maximize elegance of a k-length subsequence from a list of items with profits and categories.

困难
2816

翻倍以链表形式表示的数字

Double a number represented as a linked list by carefully managing node values and carries with pointer traversal techni…

中等
2818

操作使得分最大

Maximize the score by applying operations on a subarray at most k times, utilizing stack-based state management.

困难
2865

美丽塔 I

Solve Beautiful Towers I by testing each peak and enforcing mountain limits with monotonic stack style height propagatio…

中等
2866

美丽塔 II

Maximize tower configurations with the stack-based approach while ensuring mountain-like patterns in this medium difficu…

中等
2940

找到 Alice 和 Bob 可以相遇的建筑

Determine the leftmost building where Alice and Bob can meet using a binary search over valid move sequences.

困难
2945

找到最大非递减数组的长度

Solve Find Maximum Non-decreasing Array Length with prefix-sum DP transitions that maximize kept segments while preservi…

困难
3113

边界元素是最大值的子数组数目

Count the subarrays where the first and last elements are the largest in the subarray, utilizing binary search over vali…

困难
3170

删除星号以后字典序最小的字符串

Find the lexicographically smallest string by removing stars using stack-based state management and careful character se…

中等
3174

清除数字

Remove all digits from a given string by applying a repeated operation to form the final string without digits.

简单
3229

使数组等于目标数组所需的最少操作次数

This problem requires calculating the minimum number of operations to transform one array into another using state trans…

困难
3412

计算字符串的镜像分数

Calculate the mirror score of a string using stack-based state management for matching letters efficiently and accuratel…

中等
3420

统计 K 次操作以内得到非递减子数组的数目

This problem asks you to count non-decreasing subarrays in a given array after applying at most k operations.

困难
3430

最多 K 个元素的子数组的最值之和

Compute the sum of maximum and minimum values in all subarrays up to size k using efficient stack-based state management…

困难
3523

非递减数组的最大长度

Determine the maximum size of a non-decreasing array by replacing subarrays with their maximum values efficiently.

中等
3542

将所有元素变为 0 的最少操作次数

Calculate the fewest operations to turn all numbers in an array to zero using subarray minimum elimination strategy.

中等
3561

移除相邻字符

This problem focuses on removing adjacent characters in a string using a stack-based approach until no more operations a…

中等

关联高频模式

LeetCode 栈题型题解:140题训练路线