From b46c49228497cb440467167bad3123c327bd620f Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 17 Oct 2017 00:12:32 +0800 Subject: add --- leetcode/1_two_sum.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 leetcode/1_two_sum.c (limited to 'leetcode/1_two_sum.c') diff --git a/leetcode/1_two_sum.c b/leetcode/1_two_sum.c new file mode 100644 index 0000000..fe29ecc --- /dev/null +++ b/leetcode/1_two_sum.c @@ -0,0 +1,26 @@ +#include + +int result[2]; + +int* two_sum(int* nums, int nums_size, int target) +{ + int i, j; + for(i = 0; i < nums_size; i++) + for(j = 0; j < nums_size; j++) + if(nums[i] + nums[j] == target) { + printf("%d+%d = %d\n", nums[i], nums[j], target); + result[0] = i; + result[1] = j; + return result; + } + +} + +int main() +{ + int nums[4] = {2, 7, 11, 15}; + two_sum(nums, 4, 9); + printf("%d, %d\n",result[0], result[1]); + + return 0; +} -- cgit v1.2.3