Two Liner in Python


  • -1
    Y
    class Solution(object):
        def thirdMax(self, nums):
            nums=sorted(set(nums),reverse=True)
            return max(nums) if len(nums)<3 else min(nums[0:3])
    

  • 0
    Y

    This solution's time complexity is more than O(n) though space complexity is O(1)

    set - O(n)
    sorted - O(n log n)


Log in to reply
 

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