标签:type pytho div range solution object dash elf ret
class Solution(object): def nextGreaterElements(self, nums): """ :type nums: List[int] :rtype: List[int] """ if not nums: return if sorted(nums,reverse=True)==nums and len(set(nums))==len(nums): return [-1]+[nums[0]]*(len(nums)-1) stack=[] b=max(nums) for i in range(len(nums)): if nums[i] == b: stack.append(-1) else: j=i+1 if j==len(nums): j=0 while j<len(nums): if nums[j]>nums[i]: stack.append(nums[j]) break else: j+=1 if j==len(nums): j=0 return stack
标签:type pytho div range solution object dash elf ret
原文地址:https://www.cnblogs.com/taoyuxin/p/11783138.html