
leetcode_栈
Tim_Coder
这个作者很懒,什么都没留下…
展开
-
150.逆波兰表达式求值
题目: 思路: 代码:用switch可以简洁一点 class Solution { public int evalRPN(String[] tokens) { Stack<Integer> stack = new Stack<Integer>(); int len = tokens.length; int num1,num2; for(int i = 0;i < len;i++){原创 2020-12-03 11:12:36 · 111 阅读 · 0 评论 -
单调栈:739.每日温度 + 42.接雨水 +84.柱状图中最大的矩形
题目: 思路: ①暴力法:两个循环 ②单调栈:用栈来存放数组下标 当栈为空或当前温度小于等于栈顶索引对应的温度时,入栈 否则,出栈,日期则等于i - stack.pop() 代码: class Solution { public int[] dailyTemperatures(int[] T) { Stack<Integer> stack = new Stack<Integer>(); int len = T.length;原创 2020-12-01 16:42:28 · 98 阅读 · 0 评论