Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class N implements Comparable<N> {
- public N(int val, int pos) {
- this.val = val;
- this.pos = pos;
- }
- public int val;
- public int pos;
- @Override
- public int compareTo(N t) {
- Integer v = val;
- return v.compareTo(t.val);
- }
- }
- public static int[] suuremmat(int[] luvut) {
- int[] res = new int[luvut.length];
- Stack<N> s = new Stack<N>();
- for (int i = 0; i < luvut.length; i++) {
- int m = luvut[i];
- while (!s.empty()) {
- N n = s.peek();
- if (n.val >= m)
- break;
- res[n.pos] = m;
- s.pop();
- }
- s.push(new N(m, i));
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement