C code (This may be the simplest code...huh)


  • 0
    L
    int* twoSum(int* nums, int numsSize, int target) {
        int* returnArray = (int*)malloc(sizeof(int) * 2);
        for (int i = 0; i < numsSize; i++) {
            for (int j = i + 1; j < numsSize; j++) {
                if (nums[i] + nums[j] == target) {
                    returnArray[0] = i;
                    returnArray[1] = j;
                    break;
                }
            }
        }
        
        return returnArray;
    }
    

Log in to reply
 

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