package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/next-greater-element-i/
 */
public class Problem496 {
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int[] answer = new int[nums1.length];
        return answer;
    }

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

@@ -29,22 +29,69 @@
 va.util.
-Arrays
+HashMap;%0Aimport java.util.Map;%0Aimport java.util.Stack
 ;%0A%0A/**%0A 
@@ -252,262 +252,333 @@
     
-int%5B%5D answer = new int%5B
+Stack%3CInteger%3E stack = new Stack%3C%3E();%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 
 nums
-1
+2
 .length
-%5D;%0A        return answer;%0A
+ - 1; i %3E= 0; i--) %7B%0A    
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem496 prob = new Problem496();%0A//        System.out.println(prob.nextGreaterElement(new int%5B%5D%7B1, 5, 10%7D, new int%5B%5D%7B2, 3, 7, 11%7D)
+while (!stack.isEmpty() && nums2%5Bi%5D %3E stack.peek()) %7B%0A                stack.pop();%0A            %7D%0A            if (stack.isEmpty()) %7B%0A                map.put(nums2%5Bi%5D, -1
 );%0A 
@@ -588,223 +588,297 @@
     
+ 
-System.out.println(Arrays.toString(prob.nextGreaterElement(new int%5B%5D%7B4, 1, 2%7D, new int%5B%5D%7B1, 3, 4, 2%7D)));%0A//        System.out.println(Arrays.toString(prob.nextGreaterElement(new int%5B%5D%7B2, 4%7D, new int%5B%5D%7B1, 2, 3, 4%7D)))
+   %7D else %7B%0A                map.put(nums2%5Bi%5D, stack.peek());%0A            %7D%0A            stack.push(nums2%5Bi%5D);%0A        %7D%0A        int%5B%5D answer = new int%5Bnums1.length%5D;%0A        for (int i = 0; i %3C nums1.length; i++) %7B%0A            answer%5Bi%5D = map.get(nums1%5Bi%5D);%0A        %7D%0A        return answer
 ;%0A  

Update problem 496