aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science/leetcode
diff options
context:
space:
mode:
Diffstat (limited to 'Computer_Science/leetcode')
-rw-r--r--Computer_Science/leetcode/1_two_sum.c26
-rwxr-xr-xComputer_Science/leetcode/a.outbin0 -> 7104 bytes
2 files changed, 26 insertions, 0 deletions
diff --git a/Computer_Science/leetcode/1_two_sum.c b/Computer_Science/leetcode/1_two_sum.c
new file mode 100644
index 0000000..fe29ecc
--- /dev/null
+++ b/Computer_Science/leetcode/1_two_sum.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+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;
+}
diff --git a/Computer_Science/leetcode/a.out b/Computer_Science/leetcode/a.out
new file mode 100755
index 0000000..0aa8167
--- /dev/null
+++ b/Computer_Science/leetcode/a.out
Binary files differ