Ruby Solution


  • 0
    L
    def third_max(nums)
        a = []
        nums.each {|i|
            a << i if !a.include?(i)
            a.delete_at(a.index(a.min)) if a.length > 3
        }
        return a.length == 3 ? a.min : a.max
    end
    

Log in to reply
 

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