int* twoSum(int* nums, int numsSize, int target) {
int *result = (int *)malloc(sizeof(int) * 2); int i, j; int a, b; // looping twice will not be efficient for (i=0; i<numsSize; ++i) { a = nums[i]; for (j=i+1; j<numsSize; ++j) { b = nums[j];
int* twoSum(int* nums, int numsSize, int target, int* returnSize) { *returnSize = 2; int* result = (int*)malloc(*returnSize * sizeof(int));
// Step 1: Start the first loop to iterate over the array elements. for(int i = 0; i < numsSize; i++) { // Step 2: Start the second loop to iterate over the rest of the array elements. for(int j = i + 1; j < numsSize; j++) { // Step 3: Check if the numbers at current indices i and j add up to the target. if(nums[i] + nums[j] == target) { result[0] = i; result[1] = j; return result; } } } // Step 4: If no such indices found, return NULL and set returnSize to 0. *returnSize = 0; return NULL; }