题目链接:
LeetCode 414 — Third Maximum Number
AC代码:
public class Problem414 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] aa={2,2,3,1};
thirdMax(aa);
}
public static int thirdMax(int[] nums) {
int a=-1;int b=-1;int c=-1;
for(int i=0;i<nums.length;i++){
if(c==-1) {
c=i;
}
else{
if(nums[i]>nums[c]) {
a=b;
b=c;
c=i;
}
else if(nums[i]==nums[c]) continue;
else{
if(b==-1) {
b=i;
}
else{
if(nums[i]>nums[b]){
a=b;
b=i;
}
else if(nums[i]==nums[b]) continue;
else {
if(a==-1) {
a=i;
}
else{
if(nums[i]>nums[a]){
a=i;
}
else continue;
}
}
}
}
}
}
if(a==-1) return nums[c];
else return nums[a];
}
}