package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/next-greater-element-i/
 */
public class Problem496 {
    public int[] nextGreaterElement(int[] findNums, int[] nums) {
        // TODO
        return new int[0];
    }

    public static void main(String[] args) {
        Problem496 prob = new Problem496();
        System.out.println(Arrays.toString(prob.nextGreaterElement(new int[]{4, 1, 2}, new int[]{1, 3, 4, 2}))); // [-1,3,-1]
        System.out.println(Arrays.toString(prob.nextGreaterElement(new int[]{4, 1, 3}, new int[]{1, 3, 2, 4}))); // [-1,3,4]
        System.out.println(Arrays.toString(prob.nextGreaterElement(new int[]{4, 1, 3}, new int[]{4, 3, 2, 1}))); // [-1,-1,-1]
        System.out.println(Arrays.toString(prob.nextGreaterElement(new int[]{2, 4}, new int[]{1, 2, 3, 4}))); // [3,-1]
    }
}

@@ -34,17 +34,91 @@
 il.Array
-s
+List;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0A/**%0A 
@@ -281,636 +281,736 @@
     
-// TODO%0A        return new int%5B0%5D;
+Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B
 %0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem496 prob = new Problem496();%0A        System.out.println(Arrays.toString(prob.nextGreaterElement(new int%5B%5D%7B4, 1, 2%7D, new int%5B%5D%7B1, 3, 4, 2%7D))); // %5B-1,3,-1%5D%0A        System.out.println(Arrays.toString(prob.nextGreaterElement(new int%5B%5D%7B4, 1, 3%7D, new int%5B%5D%7B1, 3, 2, 4%7D))); // %5B-1,3,4%5D%0A        System.out.println(Arrays.toString(prob.nextGreaterElement(new int%5B%5D%7B4, 1, 3%7D, new int%5B%5D%7B4, 3, 2, 1%7D))); // %5B-1,-1,-1%5D%0A        System.out.println(Arrays.toString(prob.nextGreaterElement(new int%5B%5D%7B2, 4%7D, new int%5B%5D%7B1, 2, 3, 4%7D))); // %5B3,-1%5D
+    int num = nums%5Bi%5D;%0A            int nextGreater = -1;%0A            for (int j = i + 1; j %3C nums.length; j++) %7B%0A                if (nums%5Bi%5D %3C nums%5Bj%5D) %7B%0A                    nextGreater = nums%5Bj%5D;%0A                    break;%0A                %7D%0A            %7D%0A            map.put(nums%5Bi%5D, nextGreater);%0A        %7D%0A        List%3CInteger%3E list = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C findNums.length; i++) %7B%0A            list.add(map.get(findNums%5Bi%5D));%0A        %7D%0A        int%5B%5D result = new int%5Blist.size()%5D;%0A        for (int i = 0; i %3C result.length; i++) %7B%0A            result%5Bi%5D = list.get(i);%0A        %7D%0A        return result;
 %0A   

Solve problem 496