Accepted simple c o(n) solution


  • 0
    J

    /**

    • Note: The returned array must be malloced, assume caller calls free().
      /
      int
      twoSum(int* nums, int numsSize, int target) {
      int *ret = (int *)malloc(sizeof(int) * 2);
      for (int i = 0; i < numsSize - 1; i++) {
      int x = nums[i];
      for (int j = i+1; j < numsSize; j++) {
      if (y > target) continue;
      if (x + y == target) {
      *ret = i;
      *(ret+1) = j;
      return ret;
      }
      }
      }

      return ret;
      }


Log in to reply
 

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