#include <stdio.h>
#include <malloc.h>
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* twoSum(int* nums, int numsSize, int target, int* returnSize){
int i;
int j;
int *idx;
idx = (int*)malloc(sizeof(int) * 2);
if (idx == NULL) {
*returnSize = 0;
return NULL;
}
for (i = 0; i < numsSize; i++) {
for (j = 0; j < numsSize; j++) {
if (i != j) {
if (nums[i] + nums[j] == target) {
idx[0] = i;
idx[1] = j;
return idx;
}
}
}
}
*returnSize = 0;
return NULL;
}
int main(void) {
int nums[100] = {8, 7, 11, 2};
int numsSize = 4;
int target = 9;
int returnSize;
int *idx;
idx = twoSum(nums, numsSize, target, &returnSize);
if (idx == NULL) {
return -1;
}
if (returnSize != 0) {
printf("[%d, %d]\n", idx[0], idx[1]);
}
getch();
return 0;
}