@@ -0,0 +1,1724 @@
+/**%0A * You are given two arrays (without duplicates) nums1 and nums2 where nums1%E2%80%99s elements are subset of nums2.%0A * Find all the next greater numbers for nums1's elements in the corresponding places of nums2.%0A * The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. %0A * If it does not exist, output -1 for this number.%0A *%0A * Solution:%0A * For every number in nums1, we will call it num for simplicity, find the next greater element in nums2 by traversing from the back.%0A * We iterate from the back because as soon as we find num, we break since we only want the next element AKA the element to the right.%0A * Keep a variable that tracks the greatest element and initialize it to -1 so we do not have to check if one was found or not.%0A * Because we iterate from the back, we never have to find the index of num in nums2 since that is when we break the loop.%0A *%0A * Complexity: O(n * m) time and O(n) space %0A * where n is the length of nums1 and m is the length of nums2%0A *%0A */%0Apublic class Solution %7B%0A  public int%5B%5D nextGreaterElement(int%5B%5D findNums, int%5B%5D nums) %7B%0A    int%5B%5D res = new int%5BfindNums.length%5D;%0A%0A    for (int i = 0; i %3C findNums.length; i ++) %7B%0A      int num = findNums%5Bi%5D;%0A      int greater = -1;%0A%0A      // Iterate from back.%0A      for (int j = nums.length - 1; j %3E= 0; j --) %7B%0A%0A        // Case where we found num in nums2.%0A        if (nums%5Bj%5D == num) break;%0A%0A        // Case where we update greater.%0A        // NOTE: we do not care what the previous value of greater is%0A        // since we only want a value that is greater than num and not the absolute maximum.%0A        if (nums%5Bj%5D %3E num) greater = nums%5Bj%5D;%0A      %7D%0A      res%5Bi%5D = greater;%0A    %7D%0A%0A    return res;%0A  %7D%0A%7D%0A

Add leetcode 496