My C solution,why cant work ?


  • 0
    G

    int result = 0;
    for(int i=0; i<numsSize-1; ++i)
    {
    for(int j=i; j<numsSize; ++j)
    {
    if(nums[i] > nums[j])
    {
    nums[i] ^= nums[j];
    nums[j] ^= nums[i];
    nums[i] ^= nums[j];
    }
    }
    }
    if(numsSize <= 2)
    return nums[0];
    for(int i=0; i<numsSize/2; i+=2)
    {
    result += nums[i];
    result += nums[numsSize-2 -i];
    }
    if(numsSize/2%2 == 1)
    result -= nums[numsSize/2 -1];

    return result;


Log in to reply
 

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