Skip to content

Commit fd63757

Browse files
add problem 1
1 parent 43a40cf commit fd63757

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

C/1-Two-Sum.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include
2+
3+
/*
4+
* Note: The returned array must be malloced, assume caller calls free().
5+
* Created by supercoderhawk on 2017/7/20.
6+
*/
7+
8+
9+
int* twoSum(int* nums, int numsSize, int target) {
10+
int* indices = (int *)malloc(sizeof(int)*2);
11+
for(int i = 0;i<numsSize-1;i++)
12+
{
13+
if (nums[i]+nums[i+1]== target)
14+
{
15+
indices[0] = i;
16+
indices[1] = i + 1;
17+
}
18+
}
19+
return indices;
20+
}

0 commit comments

Comments
 (0)