
Stack
konsy_dong
Java,C++,Python,linux
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
《剑指Offer》用两个栈来实现队列
题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。思路: stack1的栈底作为队列的头,栈顶作为队列的尾,stack2来辅助pop。入队列时: 如果stack2不为空,可能是stack1过去的数据,那就就先要将stack2中的数据全都放到stack1中,然后再push。(想当于是在stack2空时,在stack1末尾push)出队列时: 如果原创 2017-03-25 00:02:07 · 284 阅读 · 0 评论 -
LeetCode 232. Implement Queue using Stacks
题目: Implement the following operations of a queue using stacks.push(x) – Push element x to the back of queue. pop() – Removes the element from in front of queue. peek() – Get the front element. emp原创 2017-04-05 09:27:22 · 346 阅读 · 0 评论 -
LeetCode 496. Next Greater Element I
题目: You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corresponding places of nums原创 2017-04-05 09:27:53 · 546 阅读 · 0 评论 -
《剑指Offer》 包含min函数的栈
题目描述: 定义栈的数据结构,请在该类型中实现一个能够得到栈最小元素的min函数。思路: 设置一个正常的栈s1,push、pop、top操作都和一般的栈一样,再设置一个用来返回最小值的栈mins,定义当栈mins为空时,或者value<=mins.top()时,value也入栈mins。在pop时,如果栈s和栈mins的top相等,则两个同时pop,否则只pop栈s。代码:class Solut原创 2017-04-07 16:39:14 · 432 阅读 · 0 评论 -
LeetCode 155. 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() –原创 2017-04-07 16:32:08 · 251 阅读 · 0 评论 -
LeetCode 20. Valid Parentheses
题目描述: Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all vali原创 2017-04-10 15:16:18 · 266 阅读 · 0 评论 -
LeetCode 225. Implement Stack using Queues
题目描述: Implement the following operations of a stack using queues.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. empty() – Return原创 2017-04-10 15:18:08 · 247 阅读 · 0 评论 -
华为机试——合并表记录
题目描述数据表记录包含表索引和数值,请对表索引相同的记录进行合并,即将相同索引的数值进行求和运算,输出按照key值升序进行输出。 输入描述: 先输入键值对的个数 然后输入成对的index和value值,以空格隔开 输出描述: 输出合并后的键值对(多行) 示例1 输入40 10 21 23 4输出0 31 23 4思路: 利用map的key值无重复:如果当前的第一个数在re原创 2017-07-25 21:57:39 · 426 阅读 · 0 评论