数组中的某个元素x的下一个大元素是同一数组中x的右边的第一个大元素.你得到了两个不同的0指数整数数组nums1和nums2,nums1是nums2的子集.对于每个0 <=i <nums1.length,找出nums1[i] ==nums2[j]的索引j,并确定nums2[j]的下一个大元素.如果没有下一个大元素,那么这个查询的答案是 -1.返回长度的数组nums1.length,以至于ans[i]是上面描述的下一个大元素.
To solve the problem, we can iterate through nums2 from right to left and use a stack to keep track of the next greater element for each element in nums2. Then, for each element in nums1, we can find its index in nums2 and return the corresponding element's next greater element from the stack. If the element does not have a next greater element, we return -1.

Here's the Python code to implement this:

```
def nextGreaterElement(nums1, nums2):
    stack = []
    next_greater = {}
    
    for num in nums2[::-1]:
        while stack and num >= stack[-1]: # pop elements from stack smaller than num
            stack.pop()
        if stack:
            next_greater[num] = stack[-1]
        else:
            next_greater[num] = -1
        stack.append(num)
    
    ans = []
    for num in nums1:
        ans.append(next_greater[num])
    
    return ans
```