zoukankan      html  css  js  c++  java
  • leetcode——503. 下一个更大元素 II

    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
    执行用时 :248 ms, 在所有 python 提交中击败了58.82%的用户
    内存消耗 :13.6 MB, 在所有 python 提交中击败了34.65%的用户
     
    ——2019.11.2
    我的前方是万里征途,星辰大海!!
  • 相关阅读:
    Python3之json文件操作
    Python3之MySQL操作
    使用requests模块的网络编程
    Python 判断小数的函数
    python之函数
    CPUID
    .inc
    probe,victim,
    coolcode
    Linux vim 常用方法
  • 原文地址:https://www.cnblogs.com/taoyuxin/p/11783138.html
Copyright © 2011-2022 走看看