https://leetcode.com/problems/evaluate-reverse-polish-notation问题:逆波兰表达式求值。思路:只需要定义一个stack,如果是+, -, *, /四个运算符,就取出栈顶的两个数,进行相应操作,之后将计算得到的结果压入栈中;如果是数字,就直接入栈。最终stack只剩下一个元素,这个元素就是逆波兰表达式的值。
leetcode.com/problems/m leetcode.com/problems/s leetcode.com/problems/l 2. Pattern: two points, 双指针类型 双指针是这样的模式:两个指针朝着左右方向移动(双指针分为同向双指针和异向双指针),直到他们有一个或是两个都满足某种条件。双指针通常用在排好序的数组或是链表中寻找对子。比如,你需要...
https://oj.leetcode.com/problems/min-stack/ 题目内容: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. getMin...
https://leetcode.com/problems/min-stack/ 题意分析: 实现一个小的栈,包括初始化,push,pop,top,和getMin。 题目思路: 思路是用两个数组来处理。 代码(python): View Code
题目地址:https://leetcode-cn.com/problems/max-stack/ 题目描述 Design a max stack that supports push, pop, top, peekMax and popMax. push(x) – Push element x onto stack. pop() – Remove the element on top of the stack and return it. ...
题目链接:https://leetcode.cn/problems/maximum-frequency-stack/题目描述:设计一个类似堆栈的数据结构,将元素推入堆栈,并从堆栈中弹出出现频率最高的元素。 实现 FreqStack 类: FreqStack() 构造一个空的堆栈。 void push(int val) 将一个整数 val 压入栈顶。 int pop() 删除并返回堆栈中… ...
给你一个整数x,如果x是一个回文整数,返回true;否则,返回false。 是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 例如,121是回文,而123不是。 示例1: 输入:x = 121输出:true 示例2: 输入:x = -121输出:false解释:从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数...
https://leetcode.com/problems/implement-queue-using-stacks/ 参考http://bookshadow.com/weblog/2015/07/07/leetcode-implement-queue-using-stacks/ 使用double stacks method or one stack method popjust remove the current element. peekreturn s the current element ...
Leetcode 分类刷题 ——栈(Stack) 1、题目描述: Leetcode 20. Valid Parentheses Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. 给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否...
0225. Implement Stack using Queues.cpp 0231. Power of Two.cpp 0260. Single Number III.cpp 0326. Power of Three.cpp 0342. Power of Four.cpp 0344. Reverse String.cpp 0345. Reverse Vowels of a String.cpp 0367. Valid Perfect Square.cpp 0371. Sum of Two Integers.cpp 0404...