an easy to understand code with c


  • 1
    J

    strikethrough text
    int deleteMax(int *nums,int len,int val)
    {
    int i=0,j=0;
    for(;i<len;i++)
    {
    if(nums[i]!=val)
    nums[j++]=nums[i];
    }
    return j;
    }
    int getMax(int *nums,int len)
    {
    int max =nums[0];
    for(int i=0;i<len;i++)
    {
    if(nums[i]>max)
    max=nums[i];
    }
    return max;
    }

    int thirdMax(int* nums, int numsSize) {
    int max = getMax(nums,numsSize);
    int tmp=max;
    int len = deleteMax(nums,numsSize,max);
    if(len==0)return tmp;
    max = getMax(nums,len);
    len =deleteMax(nums,len,max);
    if(len==0)return tmp;
    max =getMax(nums,len);
    return max;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.