/**
 * Created by wanlipeng on 2017/4/18.
 */

@@ -1,46 +1,1380 @@
 /
-**%0A * Created by wanlipeng on 2017/4/18.%0A */%0A
+/ Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).%0A//%0A// Example 1:%0A// Input: %5B3, 2, 1%5D%0A//%0A// Output: 1%0A//%0A// Explanation: The third maximum is 1.%0A// Example 2:%0A// Input: %5B1, 2%5D%0A//%0A// Output: 2%0A//%0A// Explanation: The third maximum does not exist, so the maximum (2) is returned instead.%0A//     Example 3:%0A// Input: %5B2, 2, 3, 1%5D%0A//%0A// Output: 1%0A//%0A// Explanation: Note that the third maximum here means the third maximum distinct number.%0A//     Both numbers with value 2 are both considered as second maximum.%0A%0A/**%0A * @param %7Bnumber%5B%5D%7D nums%0A * @return %7Bnumber%7D%0A */%0Avar thirdMax = function (nums) %7B%0A    function sort(arr) %7B%0A        arr.sort(function (a, b) %7B%0A            return a - b;%0A        %7D)%0A    %7D%0A    var m = new Array();%0A    for (var i in nums) %7B%0A        if (m.indexOf(nums%5Bi%5D) %3E= 0) %7B // %E5%A6%82%E6%9E%9C%E5%B7%B2%E7%BB%8F%E5%AD%98%E5%9C%A8%EF%BC%8C%E5%88%99%E7%95%A5%E8%BF%87%0A            continue;%0A        %7D%0A        if (m.length %3C 3) %7B%0A            m.push(nums%5Bi%5D)%0A        %7D else %7B%0A            if (nums%5Bi%5D %3E Math.min.apply(null, m)) %7B%0A                m.push(nums%5Bi%5D)%0A                sort(m)%0A                m.shift()%0A            %7D%0A        %7D%0A    %7D%0A    sort(m)%0A    if (m.length %3C 3) %7B%0A        return Math.max.apply(null, m);%0A    %7D%0A    return m%5B0%5D;%0A%7D;%0A%0A// Test case%0Aconsole.log(thirdMax(%5B3, 2, 1%5D))%0Aconsole.log(thirdMax(%5B2, 2, 3, 1%5D))

Add 414 Third Maximum Number