
模拟
weixin_42246923
这个作者很懒,什么都没留下…
展开
-
数组中下一个较大的元素
单调栈的思想,如果在遍历的过程中遇到了比他大的,则直接出栈。 如果没遇到更大的,则留在栈中,且遇到更大的先考虑的是栈顶的可见性。如果遍历结束后依然留在栈中的,则代表他后面没有比他更大的,则更新为-1。import java.util.*;public class NextElement { public int[] findNext(int[] A, int n) { ...原创 2018-08-13 09:32:54 · 253 阅读 · 0 评论 -
下一个更大的元素II
在后面的元素中,找一个最小的大于当前元素的。维护了一个有序栈。import java.util.*;public class NextElement { public int[] findNext(int[] A, int n) { // write code here Stack<Integer> stack1 = new Stack...原创 2018-08-13 10:32:24 · 243 阅读 · 0 评论 -
LeetCode 899. Orderly Queue
class Solution {public: string orderlyQueue(string S, int K) { if(K >= 2){ sort(S.begin(),S.end()); return S; } //else k==1 string res ...原创 2018-09-02 14:26:22 · 264 阅读 · 0 评论 -
Leetcode 1128
简单模拟,统计相同的pair个数,记得要重写hashCode方法,才能对class进行比较class Solution { static class Node { int a,b; public Node(int a, int b) { this.a = a; this.b = b; ...原创 2019-09-15 10:15:56 · 128 阅读 · 0 评论