数组中第三大的数:
class Solution { public int thirdMax(int[] nums) { int len = nums.length; int max = nums[0]; int center = nums[0]; int min = nums[0]; int swp; int[] third = new int[3]; int k= 0; boolean flag = false; for(int i=1;imax){ swp = max; max = center; center = swp; } flag = true; }else if(nums[i]!=max&&nums[i]!=center&&flag){ min = nums[i]; if(min>max){ swp = max; max = min; min = center; center = swp; }else if(min>center){ swp = center; center = min; min = swp; }else{ } k = i+1; break; }else{ } } if(k!=0){ for(int i=k;i max){ swp = max; max = nums[i]; min = center; center = swp; }else if(nums[i]>center){ swp = center; center = nums[i]; min = swp; }else{ min = nums[i]; } } return min; }else{ return max; } }}