@@ -0,0 +1,1152 @@
+package LeetCode.Java;%0A%0A/**%0A * Created by Vonzpf on 17/4/12.%0A */%0A%0Aimport java.lang.reflect.Array;%0Aimport java.util.Arrays;%0A%0A/**-------------------------Title---------------------------------%0A Given a non-empty array of integers, return the third maximum number in this array.%0A If it does not exist, return the maximum number. The time complexity must be in O(n).%0A */%0Apublic class ThirdMaximumNumber %7B%0A    public int thirdMax(int%5B%5D nums) %7B%0A        int num = 0;%0A        int thirdMax = 0;%0A        if (nums.length %3C 3)%7B%0A            if (nums.length == 1)%0A                return nums%5B0%5D;%0A            else%0A                return Math.max(nums%5B0%5D, nums%5B1%5D);%0A        %7D%0A        else %7B%0A            Arrays.sort(nums);%0A            thirdMax = nums%5Bnums.length-1%5D;%0A            num += 1;%0A            for (int j = nums.length-2; j %3E= 0; j--)%7B%0A                if (nums%5Bj%5D %3C thirdMax)%7B%0A                    thirdMax = nums%5Bj%5D;%0A                    num += 1;%0A                %7D%0A                if (num == 3)%0A                    break;%0A            %7D%0A            if (num == 3)%0A                return thirdMax;%0A            else%0A                return nums%5B0%5D;%0A        %7D%0A    %7D%0A%7D%0A

414.Third Maximum Number