Java | Leetcode Java题解之第414题第三大的数
题目:
题解:
class Solution {public int thirdMax(int[] nums) {Integer a = null, b = null, c = null;for (int num : nums) {if (a == null || num > a) {c = b;b = a;a = num;} else if (a > num && (b == null || num > b)) {c = b;b = num;} else if (b != null && b > num && (c == null || num > c)) {c = num;}}return c == null ? a : c;}
}