Python O(n*m) solution


  • 0
    C
    class Solution(object):
        def nextGreaterElement(self, findNums, nums):
            """
            :type findNums: List[int]
            :type nums: List[int]
            :rtype: List[int]
            """
            output=[]
            for item in findNums:
                found= 0
                for founditem in nums[nums.index(item):]:
                    if founditem > item and found ==0: 
                        output.append(founditem)
                        found=1
                if found==0:
                    output.append(-1)
            return output
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.