class Solution(object): def nextGreaterElement(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ for i in range(len(nums1)): if nums1[i] not in nums2: nums1[i]=-1 else: d=nums2.index(nums1[i]) if d==len(nums2)-1: nums1[i] = -1 else: j=d+1 while j<len(nums2): if nums2[j]>nums1[i]: nums1[i]=nums2[j] break else: j+=1 if j==len(nums2): nums1[i] = -1 return nums1
执行用时 :76 ms, 在所有 python 提交中击败了36.29%的用户
内存消耗 :11.8 MB, 在所有 python 提交中击败了38.18%的用户
——2019.11.2