From d2b72e52055a9214d0643a2beccb75082d0930a3 Mon Sep 17 00:00:00 2001 From: Zong <1003160664@qq.com> Date: Wed, 29 Jul 2020 12:10:13 +0800 Subject: [PATCH] Update 0001-Two-Sum.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 多版本代码实现 --- 0001-Two-Sum/Article/0001-Two-Sum.md | 88 ++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 5 deletions(-) diff --git a/0001-Two-Sum/Article/0001-Two-Sum.md b/0001-Two-Sum/Article/0001-Two-Sum.md index be84999..95e8591 100644 --- a/0001-Two-Sum/Article/0001-Two-Sum.md +++ b/0001-Two-Sum/Article/0001-Two-Sum.md @@ -37,7 +37,7 @@ ![](../Animation/Animation.gif) ### 代码实现 - +#### C++ ``` // 1. Two Sum // https://leetcode.com/problems/two-sum/description/ @@ -62,9 +62,87 @@ public: }; ``` - - - - +#### C +```c +// 1. Two Sum +// https://leetcode.com/problems/two-sum/description/ +// 时间复杂度:O(n) +// 空间复杂度:O(n) +/** + * Note: The returned array must be malloced, assume caller calls free(). + */ +int* twoSum(int* nums, int numsSize, int target, int* returnSize){ + int *ans=(int *)malloc(2 * sizeof(int)); + int i,j; + bool flag=false; + for(i=0;i