# [LeetCode]#496. Next Greater Element I

`Input: nums1 = [4,1,2], nums2 = [1,3,4,2]Output: [-1,3,-1]Explanation:For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1.For number 1 in the first array, the next greater number for it in the second array is 3.For number 2 in the first array, there is no next greater number for it in the second array, so output -1.`
1. get the nums1 value index in nums2
2. check index +1 number in nums2 is larger than nums1 or not.
3. if yes, return current value. if no, return -1.
`class Solution:    def nextGreaterElement(self,nums1, nums2):        ans=[-1]*len(nums1)             for i in nums1:            temp=nums2.index(i)            for j in range(temp,len(nums2)):                ans[nums1.index(i)]=-1if nums2[j]>i:                    ans[nums1.index(i)]=nums2[j]                    break           return ans`

--

--

--

## More from Fatboy Slim

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

## Fatboy Slim

Interesting in any computer science.