very simple python soluton


  • 0
    Z

    class Solution(object):
    def thirdMax(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    nums=set(nums)
    nums=list(nums)
    nums=sorted(nums,reverse=True)
    if len(nums)>2:
    return nums[2]
    else:
    return max(nums)


  • 0
    Z

    But when you use sorted() method, the time complexity will be O(nlgn), right?


Log in to reply
 

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