摘要:
题目链接 150. 逆波兰表达式求值 思路 从左到右遍历 tokens 遇到数字便放入栈中,遇到运算符便弹出栈顶的两个数字进行运算。 代码 class Solution{ public int evalRPN(String[] tokens){ Stack<Integer> numbers = ne 阅读全文
摘要:
题目链接 155. 最小栈 思路 让栈中的每个结点都额外存储自己入栈时的栈中最小值。这样无论何时,永远能从栈顶元素取出当前栈中的最小值。 代码 class MinStack{ // key means the number, value means the minimal number Stack< 阅读全文
摘要:
题目链接 54. 螺旋矩阵 思路 通过维护上下左右四个边界变量来控制循环。 代码 class Solution { public List<Integer> spiralOrder(int[][] matrix) { int firstRow = 0; int lastColumn = matrix 阅读全文