题解:
class Solution {
public int thirdMax(int[] nums) {
Arrays.sort(nums); // 先将数组进行排序
int count = 1; // 记录
for (int i = nums.length - 1; i > 0; i--) { // 从大到小遍历
if(nums[i] != nums[i - 1]) count++; // 不相等计数
if(count == 3) return nums[i - 1]; // 存在第三大的
}
return nums[nums.length - 1]; // 不存在第三大的
}
}