#define MP 1000
struct Node
{
int num;
int pos;
struct Node *next;
};
struct Node *hashTable[MP];
int* twoSum(int* nums, int numsSize, int target) {
int i;
memset(hashTable,0,sizeof(hashTable));
for(i = 0;i<numsSize;i++)
{
int pos = 0;
if(nums[i] < 0) pos = -nums[i]%MP;
else pos = nums[i]%MP;
struct Node *ptr = hashTable[pos];
struct Node *hashNode = malloc(sizeof(struct Node));
hashNode->num = nums[i];
hashNode->next = ptr;
hashNode->pos = i+1;
hashTable[pos] = hashNode;
}
for(i = 0 ;i<numsSize;i++)
{
int pos = 0;
int rest = target-nums[i];
if(rest < 0) pos = -rest%MP;
else pos = rest%MP;
struct Node *ptr = hashTable[pos];
while(ptr)
{
if(ptr->num == rest&&(i+1)!=ptr->pos)
{
int* result = (int*)malloc(sizeof(int*));
result[0] = i+1;
result[1] = ptr->pos;
return result;
}
ptr = ptr->next;
}
}
}