From a473f2902ff2182d7cdf6fb1adf01c03bc573b51 Mon Sep 17 00:00:00 2001 From: light-city <455954986@qq.com> Date: Wed, 5 Dec 2018 15:18:37 +0800 Subject: [PATCH 01/21] update --- readme.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/readme.md b/readme.md index 04e3dad..72c6120 100644 --- a/readme.md +++ b/readme.md @@ -6,21 +6,21 @@ | 人员 | 贡献内容 | | ---------- | ------------------------------------------------------------ | -| 光城 | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/%E5%85%89%E5%9F%8E) | -| SugarChl | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/SugarChl) | -| Archer | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/Archer) | -| ParkFeng | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/ParkFeng) | -| codingling | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/codingling) | -| muchenchen | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/muchenchen) | -| leon | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/leon) | -| HughGuo | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/HughGuo) | -| JeneYang | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/JeneYang) | -| wangggong | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/wangggong) | -| Aquila | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/Aquila) | -| Spareribs | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/Spareribs) | -| LeafScar | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/LeafScar) | -| Laqw | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/Laqw) | -| 卖萌粉松鼠 | [直通点](https://github.com/Light-City/learning-algorithm/tree/master/卖萌粉松鼠) | +| 光城 | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/%E5%85%89%E5%9F%8E) | +| SugarChl | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/SugarChl) | +| Archer | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/Archer) | +| ParkFeng | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/ParkFeng) | +| codingling | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/codingling) | +| muchenchen | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/muchenchen) | +| leon | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/leon) | +| HughGuo | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/HughGuo) | +| JeneYang | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/JeneYang) | +| wangggong | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/wangggong) | +| Aquila | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/Aquila) | +| Spareribs | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/Spareribs) | +| LeafScar | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/LeafScar) | +| Laqw | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/Laqw) | +| 卖萌粉松鼠 | [直通点](https://github.com/guangcity/learning-algorithm/tree/master/卖萌粉松鼠) | | | | | | | | | | From abfeb4339aec312fd9e165ca141bdc97d20bbd11 Mon Sep 17 00:00:00 2001 From: missannas <42210208+missannas@users.noreply.github.com> Date: Wed, 5 Dec 2018 15:59:32 +0800 Subject: [PATCH 02/21] Create miss-ann --- miss-ann | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 miss-ann diff --git a/miss-ann b/miss-ann new file mode 100644 index 0000000..59d0088 --- /dev/null +++ b/miss-ann @@ -0,0 +1,161 @@ +Leetcode+两数之和 小安晋升分享(第一题哦) + +# 两数之和 + +今天是小安开始Leetcode刷题的第一天,一定要加油o.废话不多,进入正文啦…@-@ + +## 题目描述 +给定一个整数数组 *nums* 和一个目标值*target*,请你在该数组中找出和为目标值的两个**整数**。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。[题目原址](https://leetcode-cn.com/problems/two-sum/solution/) +**示例** + +> 给定 nums = [2, 7, 11, 15],target = 9 +> 因为 nums[0] +nums[1] =2+7 =9 +> 所以返回 [0,1] + +## 方法一:暴力解法 + +### 思想 +暴力法很简单。遍历每个元素 xx,并查找是否存在一个值与 target - xtarget−x 相等的目标元素。 + +### 代码实现 +【C实现】 + +``` +/** + * Note: The returned array must be malloced, assume caller calls free(). + */ +int* twoSum(int* nums, int numsSize, int target) { + static int a[2]={0,0}; + for (int i=0;i map = new HashMap<>(); + for (int i = 0; i < nums.length; i++) { + map.put(nums[i], i);//将每个元素的值和他的索引添加到表中 + } + for (int i = 0; i < nums.length; i++) { + int tmp = target - nums[i]; + if (map.containsKey(tmp) && map.get(tmp) != i) { + return new int[] { i, map.get(tmp) }; + } + } + throw new IllegalArgumentException("No two sum solution");//异常抛出 + } +} +``` + + +### 复杂度分析 + + - 时间复杂度:$O(n)$, 我们把包含有 $n$个元素的列表遍历两次。由于哈希表将查找时间缩短到 $O(1)$,所以时间复杂度为 $O(n)$。 + - 空间复杂度:$O(n)$, 所需的额外空间取决于哈希表中存储的元素数量,该表中存储了$n$ 个元素。 +## 方法三:一遍哈希表 +### 思想 +事实证明,我们可以一次完成。在进行迭代并将元素插入到表中的同时,我们还会回过头来检查表中是否已经存在当前元素所对应的目标元素。如果它存在,那我们已经找到了对应解,并立即将其返回。 +### 代码实现 +【Java实现】 + +``` +class Solution { + public int[] twoSum(int[] nums, int target) { + Map map = new HashMap<>(); + for (int i = 0; i < nums.length; i++) { + int tmp = target - nums[i]; + if (map.containsKey(tmp)) { + return new int[] { map.get(tmp), i }; + } + map.put(nums[i], i); + } + throw new IllegalArgumentException("No two sum solution"); + } +} +``` +【python实现】 + +``` +class Solution: + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + if not nums: + return None + d ={} + for i,item in enumerate(nums): + tmp = target - item + for key,value in d.items(): + if value == tmp: + return [i,key] + + d[i] = item + return None + +``` +### 复杂度分析 + + - 时间复杂度:$O(n)$, 我们只遍历了包含有$n$个元素的列表一次。在表中进行的每次查找只花费 $O(1)$的时间。 + - 空间复杂度:$O(n)$, 所需的额外空间取决于哈希表中存储的元素数量,该表最多需要存$n$个元素。 + + +# Thanks +一起加油哦~~ From 538b7d8f560a433761a779c965ad74ab8797f222 Mon Sep 17 00:00:00 2001 From: missannas <42210208+missannas@users.noreply.github.com> Date: Wed, 5 Dec 2018 16:24:38 +0800 Subject: [PATCH 03/21] Delete miss-ann --- miss-ann | 161 ------------------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 miss-ann diff --git a/miss-ann b/miss-ann deleted file mode 100644 index 59d0088..0000000 --- a/miss-ann +++ /dev/null @@ -1,161 +0,0 @@ -Leetcode+两数之和 小安晋升分享(第一题哦) - -# 两数之和 - -今天是小安开始Leetcode刷题的第一天,一定要加油o.废话不多,进入正文啦…@-@ - -## 题目描述 -给定一个整数数组 *nums* 和一个目标值*target*,请你在该数组中找出和为目标值的两个**整数**。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。[题目原址](https://leetcode-cn.com/problems/two-sum/solution/) -**示例** - -> 给定 nums = [2, 7, 11, 15],target = 9 -> 因为 nums[0] +nums[1] =2+7 =9 -> 所以返回 [0,1] - -## 方法一:暴力解法 - -### 思想 -暴力法很简单。遍历每个元素 xx,并查找是否存在一个值与 target - xtarget−x 相等的目标元素。 - -### 代码实现 -【C实现】 - -``` -/** - * Note: The returned array must be malloced, assume caller calls free(). - */ -int* twoSum(int* nums, int numsSize, int target) { - static int a[2]={0,0}; - for (int i=0;i map = new HashMap<>(); - for (int i = 0; i < nums.length; i++) { - map.put(nums[i], i);//将每个元素的值和他的索引添加到表中 - } - for (int i = 0; i < nums.length; i++) { - int tmp = target - nums[i]; - if (map.containsKey(tmp) && map.get(tmp) != i) { - return new int[] { i, map.get(tmp) }; - } - } - throw new IllegalArgumentException("No two sum solution");//异常抛出 - } -} -``` - - -### 复杂度分析 - - - 时间复杂度:$O(n)$, 我们把包含有 $n$个元素的列表遍历两次。由于哈希表将查找时间缩短到 $O(1)$,所以时间复杂度为 $O(n)$。 - - 空间复杂度:$O(n)$, 所需的额外空间取决于哈希表中存储的元素数量,该表中存储了$n$ 个元素。 -## 方法三:一遍哈希表 -### 思想 -事实证明,我们可以一次完成。在进行迭代并将元素插入到表中的同时,我们还会回过头来检查表中是否已经存在当前元素所对应的目标元素。如果它存在,那我们已经找到了对应解,并立即将其返回。 -### 代码实现 -【Java实现】 - -``` -class Solution { - public int[] twoSum(int[] nums, int target) { - Map map = new HashMap<>(); - for (int i = 0; i < nums.length; i++) { - int tmp = target - nums[i]; - if (map.containsKey(tmp)) { - return new int[] { map.get(tmp), i }; - } - map.put(nums[i], i); - } - throw new IllegalArgumentException("No two sum solution"); - } -} -``` -【python实现】 - -``` -class Solution: - def twoSum(self, nums, target): - """ - :type nums: List[int] - :type target: int - :rtype: List[int] - """ - if not nums: - return None - d ={} - for i,item in enumerate(nums): - tmp = target - item - for key,value in d.items(): - if value == tmp: - return [i,key] - - d[i] = item - return None - -``` -### 复杂度分析 - - - 时间复杂度:$O(n)$, 我们只遍历了包含有$n$个元素的列表一次。在表中进行的每次查找只花费 $O(1)$的时间。 - - 空间复杂度:$O(n)$, 所需的额外空间取决于哈希表中存储的元素数量,该表最多需要存$n$个元素。 - - -# Thanks -一起加油哦~~ From 7a812e00b01032799709ca7c434a5d56b25ba07f Mon Sep 17 00:00:00 2001 From: missannas <42210208+missannas@users.noreply.github.com> Date: Wed, 5 Dec 2018 16:28:09 +0800 Subject: [PATCH 04/21] Create al1.c --- miss-ann/two_sum/al1/al1.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 miss-ann/two_sum/al1/al1.c diff --git a/miss-ann/two_sum/al1/al1.c b/miss-ann/two_sum/al1/al1.c new file mode 100644 index 0000000..c5a8cbd --- /dev/null +++ b/miss-ann/two_sum/al1/al1.c @@ -0,0 +1,17 @@ +/** + * Note: The returned array must be malloced, assume caller calls free(). + */ +int* twoSum(int* nums, int numsSize, int target) { + static int a[2]={0,0}; + for (int i=0;i Date: Wed, 5 Dec 2018 16:34:18 +0800 Subject: [PATCH 05/21] test-pr --- .idea/learning-algorithm.iml | 11 ++ .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 174 ++++++++++++++++++ .../delete_duplicate/deltete_duplicate.py | 30 +++ woyaoyangguang/delete_duplicate/readme.md | 5 + 7 files changed, 241 insertions(+) create mode 100644 .idea/learning-algorithm.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 woyaoyangguang/delete_duplicate/deltete_duplicate.py create mode 100644 woyaoyangguang/delete_duplicate/readme.md diff --git a/.idea/learning-algorithm.iml b/.idea/learning-algorithm.iml new file mode 100644 index 0000000..e9de3de --- /dev/null +++ b/.idea/learning-algorithm.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2012045 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3627932 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..24eabd1 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +