Advertisement
Rochet2

Untitled

Feb 3rd, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1.     public static class N implements Comparable<N> {
  2.  
  3.         public N(int val, int pos) {
  4.             this.val = val;
  5.             this.pos = pos;
  6.         }
  7.  
  8.         public int val;
  9.         public int pos;
  10.  
  11.         @Override
  12.         public int compareTo(N t) {
  13.             Integer v = val;
  14.             return v.compareTo(t.val);
  15.         }
  16.     }
  17.  
  18.     public static int[] suuremmat(int[] luvut) {
  19.         int[] res = new int[luvut.length];
  20.         Stack<N> s = new Stack<N>();
  21.         for (int i = 0; i < luvut.length; i++) {
  22.             int m = luvut[i];
  23.              
  24.             while (!s.empty()) {
  25.                 N n = s.peek();
  26.                 if (n.val >= m)
  27.                     break;
  28.                 res[n.pos] = m;
  29.                 s.pop();
  30.             }
  31.              
  32.             s.push(new N(m, i));
  33.         }
  34.         return res;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement