concise c solution


  • 3
    B
    int thirdMax(int* nums, int numsSize) {
        long max1, max2, max3;
        int i;
        for (max1 = max2 = max3 = LONG_MIN, i = 0; i < numsSize; i++) {
            if (max3 >= nums[i] || max1 == nums[i] || max2 == nums[i])
                continue;
            max3 = nums[i];
            if (max2 < max3)
                swap(&max2, &max3);
            if (max1 < max2)
                swap(&max1, &max2);
        }
        return max3 == LONG_MIN ? max1 : max3;
    }
    

Log in to reply
 

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