Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int* twoSum(int* nums, int numsSize, int target, int* returnSize){
- int *indices = malloc(sizeof(int) * 2);
- *returnSize = 2;
- int *hash = calloc(target+1, sizeof(int));
- for(int i = 0; i<numsSize; i++){
- if(target>=nums[i]){
- if(hash[target-nums[i]] == 0){
- hash[nums[i]] = i+1;
- }
- else{
- indices[0] = hash[target-nums[i]] - 1;
- indices[1] = i;
- free(hash);
- return indices;
- }
- }
- }
- free(hash);
- return indices;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement