# 问题描述

You are given two arrays(without duplicates)`nums1`and`nums2`where`nums1`’s elements are subset of`nums2`. Find all the next greater numbers for`nums1`'s elements in the corresponding places of`nums2`.

The Next Greater Number of a numberxin`nums1`is the first greater number to its right in`nums2`. If it does not exist, output -1 for this number.

# Java

`public class Solution {    public int[] nextGreaterElement(int[] findNums, int[] nums) {        Stack<Integer> stack = new Stack<>();        for (int i = nums.length - 1; i >= 0; i--) {            stack.push(nums[i]);        }​        int[] result = new int[findNums.length];        int i = 0;        for (int findNum : findNums) {            result[i++] = findGreater(findNum, stack);        }        return result;    }​    int findGreater(int findNum, Stack<Integer> stack) {        Stack<Integer> stackClone = (Stack<Integer>) stack.clone();        boolean isFindNum = false;        while (!stackClone.isEmpty()) {            int num = stackClone.pop();            if (num == findNum) {                isFindNum = true;            }            if (isFindNum && num > findNum) {                return num;            }        }        return -1;    }}`