摘要: 单调栈实际上就是栈,只是利用了一些巧妙的逻辑,使得每次新元素入栈后,栈内的元素都保持有序(单调递增或单调递减)。 单调栈用途不太广泛,只处理一种典型的问题,叫做 Next Greater Element。 阅读全文
posted @ 2019-06-15 22:36 Austin_anheqiao 阅读(155) 评论(1) 推荐(0) 编辑
摘要: 方法一 先遍历nums2,将每个元素后面第一个大的元素一起存入到map中,然后在遍历nums1,在map中找到。 阅读全文
posted @ 2019-06-15 21:46 Austin_anheqiao 阅读(315) 评论(0) 推荐(0) 编辑
摘要: 1 class MyQueue { 2 public: 3 /** Initialize your data structure here. */ 4 MyQueue() { 5 6 } 7 stack a; 8 stack b; 9 /** Push element x to the back of queu... 阅读全文
posted @ 2019-06-15 19:43 Austin_anheqiao 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 1 class MyStack { 2 public: 3 queue q; 4 /** Initialize your data structure here. */ 5 MyStack() { 6 7 } 8 /* 9 -------------- 10 push pop 11 ... 阅读全文
posted @ 2019-06-15 19:42 Austin_anheqiao 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 1 class MinStack { 2 public: 3 /** initialize your data structure here. */ 4 MinStack() { 5 6 } 7 stack s; 8 void push(int x) { 9 if(s.empty() || xpush(... 阅读全文
posted @ 2019-06-15 18:58 Austin_anheqiao 阅读(146) 评论(0) 推荐(0) 编辑