package leetcode;

/**
 * https://leetcode.com/problems/next-greater-element-ii/
 */
public class Problem503 {
    public int[] nextGreaterElements(int[] nums) {
        // TODO
        return new int[0];
    }

    public static void main(String[] args) {
        Problem503 prob = new Problem503();
        System.out.println(prob.nextGreaterElements(new int[]{1, 2, 1})); // [2,-1,2]
    }
}

@@ -167,224 +167,662 @@
     
-// TODO%0A        return new int%5B0%5D;%0A
+int%5B%5D result = new int%5Bnums.length%5D;%0A        int max = Integer.MIN_VALUE;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            max = Math.max(nums%5Bi%5D, max);%0A   
     
+ 
 %7D
-%0A
 %0A    
-public static void main(String%5B%5D args) %7B%0A        Problem503 prob = new Problem503();%0A        System.out.println(prob.nextGreaterElements(new int%5B%5D%7B1, 2, 1%7D)); // %5B2,-1,2%5D
+    for (int i = 0; i %3C nums.length; i++) %7B%0A            if (nums%5Bi%5D == max) %7B%0A                result%5Bi%5D = -1;%0A                continue;%0A            %7D%0A            int j = i + 1;%0A            if (j == nums.length) %7B%0A                j = 0;%0A            %7D%0A            while (nums%5Bi%5D %3E= nums%5Bj%5D) %7B%0A                j++;%0A                if (j == nums.length) %7B%0A                    j = 0;%0A                %7D%0A            %7D%0A            result%5Bi%5D = nums%5Bj%5D;%0A        %7D%0A        return result;
 %0A   

Solve problem 503