返回数组中最大的三个数

class Solution:
    def maxThreeNum(self, nums: List[int]):
        n1, n2, n3 = 0
        for i in range(len(nums)):
            if nums[i] > n1:
                n2 = n1
                n1 = nums[i]
            elif nums[i] > n2:
                n3 = n2
                n2 = nums[i]
            elif nums[i] > n3:
                n3 = nums[i]
        return n1, n2, n3 

 

posted @ 2020-06-29 10:10  how333  阅读(578)  评论(0编辑  收藏  举报