How can we find second maximum from array efficiently?

前端 未结 16 1137
Happy的楠姐
Happy的楠姐 2020-12-25 14:39

Is it possible to find the second maximum number from an array of integers by traversing the array only once?

As an example, I have a array of five integers from whi

16条回答
  •  执笔经年
    2020-12-25 15:12

    int max,secondMax;
    max=secondMax=array[0];
                                                    for(int i=0;imax)                                                    {                                           max=array[i];                                                   }
                                                            if(array[i]>secondMax && array[i]

提交回复
热议问题