Advertisement
Guest User

123

a guest
Jan 29th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. int* twoSum(int* nums, int numsSize, int target, int* returnSize){
  2. int *indices = malloc(sizeof(int) * 2);
  3. *returnSize = 2;
  4. int *hash = calloc(target+1, sizeof(int));
  5. for(int i = 0; i<numsSize; i++){
  6. if(target>=nums[i]){
  7. if(hash[target-nums[i]] == 0){
  8. hash[nums[i]] = i+1;
  9. }
  10. else{
  11. indices[0] = hash[target-nums[i]] - 1;
  12. indices[1] = i;
  13. free(hash);
  14. return indices;
  15. }
  16. }
  17. }
  18. free(hash);
  19. return indices;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement