From d2e40a411b7ea013ffac9294216e5477052713b2 Mon Sep 17 00:00:00 2001 From: Standard Box Date: Thu, 12 Oct 2023 15:33:24 +0530 Subject: [PATCH] Added 2 Sum Problem --- .../src/leetcode/two_sum_problem/Two_Sum.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 code/online_challenges/src/leetcode/two_sum_problem/Two_Sum.c diff --git a/code/online_challenges/src/leetcode/two_sum_problem/Two_Sum.c b/code/online_challenges/src/leetcode/two_sum_problem/Two_Sum.c new file mode 100644 index 0000000000..838caa2908 --- /dev/null +++ b/code/online_challenges/src/leetcode/two_sum_problem/Two_Sum.c @@ -0,0 +1,15 @@ +int* twoSum(int* nums, int numsSize, int target, int* returnSize) +{ + * returnSize = 2; + int * res; + res = (int*)malloc(2 * sizeof(int)); + for(int i = 0; i < numsSize; i++) { + for(int j = i + 1; j < numsSize; j++) { + if((nums[i] + nums[j]) == target) { + res[0] = i; + res[1] = j; + } + } + } + return res; +} \ No newline at end of file