diff --git a/DataStructureAndAlgorithm/02 C#语言基本语法结构.md b/CSharpLanguage/01 C#语言基本语法结构.md
similarity index 99%
rename from DataStructureAndAlgorithm/02 C#语言基本语法结构.md
rename to CSharpLanguage/01 C#语言基本语法结构.md
index 2fe90a7..c34117f 100644
--- a/DataStructureAndAlgorithm/02 C#语言基本语法结构.md
+++ b/CSharpLanguage/01 C#语言基本语法结构.md
@@ -1,4 +1,4 @@
-# 02 C#Իṹ
+# 01 C#Իṹ
**֪ʶṹ**
diff --git a/DataStructureAndAlgorithm/03 C#面向对象设计 I.md b/CSharpLanguage/02 C#面向对象设计 I.md
similarity index 99%
rename from DataStructureAndAlgorithm/03 C#面向对象设计 I.md
rename to CSharpLanguage/02 C#面向对象设计 I.md
index 5be955f..2869bd4 100644
--- a/DataStructureAndAlgorithm/03 C#面向对象设计 I.md
+++ b/CSharpLanguage/02 C#面向对象设计 I.md
@@ -1,4 +1,4 @@
-# 03 C# I
+# 02 C# I
**֪ʶṹ**
diff --git a/DataStructureAndAlgorithm/04 C#面向对象设计 II.md b/CSharpLanguage/03 C#面向对象设计 II.md
similarity index 99%
rename from DataStructureAndAlgorithm/04 C#面向对象设计 II.md
rename to CSharpLanguage/03 C#面向对象设计 II.md
index d5fce42..15761af 100644
--- a/DataStructureAndAlgorithm/04 C#面向对象设计 II.md
+++ b/CSharpLanguage/03 C#面向对象设计 II.md
@@ -1,7 +1,7 @@
-# 04 C# II
+# 03 C# II
**֪ʶṹ**
diff --git a/DataStructureAndAlgorithm/01 绪论.md b/DataStructureAndAlgorithm/01 绪论.md
index 808f726..46a7e1c 100644
--- a/DataStructureAndAlgorithm/01 绪论.md
+++ b/DataStructureAndAlgorithm/01 绪论.md
@@ -1,4 +1,4 @@
-#
+# 01
֪ʶṹ
diff --git a/DataStructureAndAlgorithm/06 线性表.md b/DataStructureAndAlgorithm/02 线性表.md
similarity index 99%
rename from DataStructureAndAlgorithm/06 线性表.md
rename to DataStructureAndAlgorithm/02 线性表.md
index 10ed27f..f32fecc 100644
Binary files a/DataStructureAndAlgorithm/06 线性表.md and b/DataStructureAndAlgorithm/02 线性表.md differ
diff --git a/DataStructureAndAlgorithm/09 栈与递归.md b/DataStructureAndAlgorithm/03 栈与递归.md
similarity index 99%
rename from DataStructureAndAlgorithm/09 栈与递归.md
rename to DataStructureAndAlgorithm/03 栈与递归.md
index 97b9f62..ce0cd09 100644
--- a/DataStructureAndAlgorithm/09 栈与递归.md
+++ b/DataStructureAndAlgorithm/03 栈与递归.md
@@ -1,6 +1,6 @@
-# 09 ջݹ
+# 03 ջݹ
**֪ʶṹ**
@@ -16,7 +16,7 @@
루ջɾջֻһˣջеԱȽFirst In Last OutԱ
-1 Ա`$(a_0,a_1,?,a_{n-1)}$`ջջʾ
+1 Ա $(a_0,a_1,?,a_{n-1)}$ ջջʾ

diff --git a/DataStructureAndAlgorithm/10 队列与多线程.md b/DataStructureAndAlgorithm/04 队列与多线程.md
similarity index 99%
rename from DataStructureAndAlgorithm/10 队列与多线程.md
rename to DataStructureAndAlgorithm/04 队列与多线程.md
index 625b88f..37bcb2f 100644
--- a/DataStructureAndAlgorithm/10 队列与多线程.md
+++ b/DataStructureAndAlgorithm/04 队列与多线程.md
@@ -1,5 +1,5 @@
-# 10 ߳
+# 04 ߳
**֪ʶṹ**
diff --git a/DataStructureAndAlgorithm/05 Leetcode同步练习(一).md b/DataStructureAndAlgorithm/05 Leetcode同步练习(一).md
deleted file mode 100644
index 561b9dc..0000000
--- a/DataStructureAndAlgorithm/05 Leetcode同步练习(一).md
+++ /dev/null
@@ -1,791 +0,0 @@
-
-# Leetcodeͬϰһ
-
-## Ŀ01֮
-
-> - ţ1
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/two-sum/
-
-һ `nums` һĿֵ `target`ڸҳΪĿֵ ǵ±ꡣ
-
-ԼÿֻӦһ𰸡ǣ㲻ظͬԪء
-
-**ʾ1:**
-
-```c
- nums = [2, 7, 11, 15], target = 9
-
-Ϊ nums[0] + nums[1] = 2 + 7 = 9Է [0, 1]
-```
-
-**ʾ2**
-
-```c
- nums = [230, 863, 916, 585, 981, 404, 316, 785, 88, 12, 70, 435, 384, 778, 887, 755, 740, 337, 86, 92, 325, 422, 815, 650, 920, 125, 277, 336, 221, 847, 168, 23, 677, 61, 400, 136, 874, 363, 394, 199, 863, 997, 794, 587, 124, 321, 212, 957, 764, 173, 314, 422, 927, 783, 930, 282, 306, 506, 44, 926, 691, 568, 68, 730, 933, 737, 531, 180, 414, 751, 28, 546, 60, 371, 493, 370, 527, 387, 43, 541, 13, 457, 328, 227, 652, 365, 430, 803, 59, 858, 538, 427, 583, 368, 375, 173, 809, 896, 370, 789], target = 542
-
-Ϊ nums[28] + nums[45] = 221 + 321 = 542Է [28, 45]
-```
-
-**ο룺**
-
-˼·ֱñƥ㷨
-
-- ִнͨ
-- ִʱ432 ms, C# ύл 65.82% û
-- ڴģ30.8 MB, C# ύл 8.67% û
-
-```c
-public class Solution
-{
- public int[] TwoSum(int[] nums, int target)
- {
- int[] result = new int[2];
- for (int i = 0; i < nums.Length - 1; i++)
- {
- int find = target - nums[i];
- for (int j = i + 1; j < nums.Length; j++)
- {
- if (find == nums[j])
- {
- result[0] = i;
- result[1] = j;
- return result;
- }
- }
- }
- return result;
- }
-}
-```
-
-
----
-## Ŀ02ɾеظ
-
-> - ţ26
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
-
-һ ****Ҫ **ԭ** ɾظֵԪأʹÿԪֻһΣƳ³ȡ
-
-Ҫʹöռ䣬 **ԭ** ʹ O(1) ռɡ
-
-ʾ 1:
-
-```c
- nums = [1,1,2],
-Ӧ÷µij 2, ԭ nums ǰԪرΪ 1, 2
-㲻Ҫг³ȺԪء
-```
-
-ʾ 2:
-
-```c
- nums = [0,0,1,1,1,2,2,3,3,4],
-Ӧ÷µij 5, ԭ nums ǰԪرΪ 0, 1, 2, 3, 4
-㲻Ҫг³ȺԪء
-```
-
-˵:
-
-ΪʲôֵĴ?
-
-ע⣬ԡ****ʽݵģζںڵǿɼġ
-
-ڲ:
-
-```c
-// nums ԡáʽݵġҲ˵ʵκο
-int len = removeDuplicates(nums);
-
-// ںڵǿɼġ
-// ĺصij, ӡиóȷΧڵԪء
-for (int i = 0; i < len; i++) {
- print(nums[i]);
-}
-```
-
-
-
-**ο룺**
-
-˼·˫һһ`j``i``nums[j] == nums[i]`ʱ`j++`Ϳظʱ`i++``nums[i] = nums[j]`ֵƹִеĩβɣʱ临ӶΪ`O(n)`
-
-- ִнͨ
-- ִʱ300 ms, C# ύл 64.43% û
-- ڴģ33.5 MB, C# ύл 5.48% û
-
-```c
-public class Solution
-{
- public int RemoveDuplicates(int[] nums)
- {
- if (nums.Length < 2)
- return nums.Length;
-
- int i = 0;
- for (int j = 1; j < nums.Length; j++)
- {
- if (nums[j] != nums[i])
- {
- i++;
- nums[i] = nums[j];
- }
- }
- return i + 1;
- }
-}
-```
-
----
-## Ŀ03ƳԪ
-
-> - ţ27
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/remove-element/
-
-
-һ`nums`һֵ`val`Ҫ**ԭ**Ƴֵ`val`ԪأƳ³ȡ
-
-Ҫʹöռ䣬**ԭ**ʹ O(1) ռɡ
-
-Ԫص˳Ըı䡣㲻Ҫг³ȺԪء
-
-**ʾ 1:**
-
-```c
- nums = [3,2,2,3], val = 3,
-
-Ӧ÷µij 2, nums еǰԪؾΪ 2
-
-㲻Ҫг³ȺԪء
-```
-
-**ʾ 2:**
-
-```c
- nums = [0,1,2,2,3,0,4,2], val = 2,
-
-Ӧ÷µij 5, nums еǰԪΪ 0, 1, 3, 0, 4
-
-עԪؿΪ˳
-
-㲻Ҫг³ȺԪء
-```
-
-**ʾ 3:**
-```c
-룺[] value = 0
-
-0
-```
-
-**ʾ 4:**
-```c
-룺[1] value = 1
-
-0
-```
-
-**ʾ 5:**
-
-```c
-룺[4,5] value = 5
-
-1
-```
-
-
-
-**˵:**
-
-ΪʲôֵĴ?
-
-ע⣬ԡ****ʽݵģζںڵǿɼġ
-
-ڲ:
-
-```c
-// nums ԡáʽݵġҲ˵ʵκο
-int len = removeElement(nums, val);
-
-// ںڵǿɼġ
-// ĺصij, ӡиóȷΧڵԪء
-for (int i = 0; i < len; i++) {
- print(nums[i]);
-}
-```
-
-**ο룺**
-
-˼·˫˫`i``j``i`ΪϺ`j`Ϊǰ塣`nums[j]!=val``num[j]`ֵ`num[i]`ѭ`i`ָǰԪأΪҪԪأӶﵽƳԪصĿģʱ临ӶΪ `O(n)`
-
-- ִнͨ
-- ִʱ272 ms, C# ύл 94.41% û
-- ڴģ29.9 MB, C# ύл 5.21% û
-
-```c
-public class Solution
-{
- public int RemoveElement(int[] nums, int val)
- {
- int i = 0;
- for (int j = 0; j < nums.Length; j++)
- {
- if (nums[j] != val)
- {
- nums[i] = nums[j];
- i++;
- }
- }
- return i;
- }
-}
-```
-
-
----
-## Ŀ04
-
-> - ţ53
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/maximum-subarray/
-
-һ`nums`ҵһ͵飨ٰһԪأ͡
-
-ʾ 1:
-```c
-: [-2,1,-3,4,-1,2,1,-5,4],
-: 6
-: [4,-1,2,1] ĺΪ 6
-```
-
-ʾ 2:
-```c
-: [-2,1],
-: 1
-```
-
-:
-
-ѾʵָӶΪ`O(n)`ĽⷨʹøΪķη⡣
-
-**ο룺**
-
-˼·ñ㷨
-
-- ״̬ͨ
-- ִʱ: 596 ms, C# ύл 14.18% û
-- ڴ: 24.5 MB, C# ύл 5.88% û
-
-```c
-public class Solution {
- public int MaxSubArray(int[] nums) {
- int len = nums.Length;
- if (len == 0)
- return 0;
- if (len == 1)
- return nums[0];
- int max = int.MinValue;
-
- for (int i = 0; i < len; i++)
- {
- int sum = nums[i];
- if (sum > max)
- {
- max = sum;
- }
- for (int j = i + 1; j < len; j++)
- {
- sum += nums[j];
- if (sum > max)
- {
- max = sum;
- }
- }
- }
- return max;
- }
-}
-```
-
----
-## Ŀ05ʢˮ
-
-
-> - ţ11
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/container-with-most-water/
-
-`n`Ǹ`a1a2...an`ÿеһ`(i, ai)`ڻ`n`ֱߣֱ`i` ˵ֱΪ`(i, ai)``(i, 0)`ҳеߣʹ`x`Ṳͬɵˮ
-
-˵㲻б`n`ֵΪ 2
-
-
-
-ͼдֱߴ [1,8,6,2,5,4,8,3,7]ڴ£ܹˮʾΪɫֵ֣Ϊ 49
-
-ʾ:
-```c
-: [1,8,6,2,5,4,8,3,7]
-: 49
-```
-
-
-**ο룺**
-
-˼·˫ķ
-
-
-
-0-7ߵ1-7һΪΪʲô0-6һ֧
-
-```c
-h(i)ʾi߶εĸ߶ȣS(ij)ʾi߶κ͵j߶Ȧ
-
-֪ h(0) < h(7)ӶS(07) = h(0) * 7
-
-S(06) = min(h(0), h(6)) * 6
-
-h(0) <= h(6)S(06) = h(0) * 6
-h(0) > h(6)S(06) = h(6) * 6S(06) < h(0) * 6
-
-ɴ˿֪S(06)ȻСS(07)
-```
-ÿһͬķ֪˫ߵ·
-
-- ״̬ͨ
-- 50 / 50 ͨ
-- ִʱ: 144 ms, C# ύл 99.64% û
-- ڴ: 26.6 MB, C# ύл 5.45% û
-
-```c
-public class Solution
-{
- public int MaxArea(int[] height)
- {
- int i = 0, j = height.Length - 1;
- int max = int.MinValue;
- while (i < j)
- {
- int temp = (j - i) * Math.Min(height[i], height[j]);
- if (temp > max)
- {
- max = temp;
- }
- if (height[i] < height[j])
- {
- i++;
- }
- else
- {
- j--;
- }
- }
- return max;
- }
-}
-```
-
----
-## Ŀ06ת
-
-> - ţ33
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/search-in-rotated-sorted-array/
-
-谴Ԥδ֪ijϽת
-
-( 磬 [0,1,2,4,5,6,7] ܱΪ [4,5,6,7,0,1,2] )
-
-һĿֵдĿֵ -1
-
-ԼвظԪء
-
-㷨ʱ临Ӷȱ`O(log n)`
-
-ʾ 1:
-```c
-: nums = [4,5,6,7,0,1,2], target = 0
-: 4
-```
-
-ʾ 2:
-```c
-: nums = [4,5,6,7,0,1,2], target = 3
-: -1
-```
-
-ʾ 3:
-```c
-: nums = [5,1,3], target = 5
-: 0
-```
-
-ʾ 4:
-```c
-: nums = [4,5,6,7,8,1,2,3], target = 8
-: 4
-```
-
-ʾ 5:
-```c
-: nums = [3,1], target = 1
-: 1
-```
-
-**ο룺**
-
-˼·öַ
-
-- ״̬ͨ
-- ִʱ: 128 ms, C# ύл 97.17% û
-- ڴ: 23.8 MB, C# ύл 12.00% û
-
-```c
-public class Solution
-{
- public int Search(int[] nums, int target)
- {
- int i = 0, j = nums.Length - 1;
- while (i <= j)
- {
- int mid = (i + j) / 2;
- if (nums[mid] == target)
- return mid;
-
- if (nums[mid] >= nums[i])
- {
- //벿
- if (target > nums[mid])
- {
- i = mid + 1;
- }
- else
- {
- if (target == nums[i])
- return i;
-
- if (target > nums[i])
- j = mid - 1;
- else
- i = mid + 1;
- }
- }
- else
- {
- if (target < nums[mid])
- {
- j = mid - 1;
- }
- else
- {
- if (target == nums[j])
- return j;
- if (target < nums[j])
- i = mid + 1;
- else
- j = mid - 1;
- }
- }
- }
- return -1;
- }
-}
-```
-
-
-
-
-
----
-## Ŀ07еĵKԪ
-
-> - ţ215
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/kth-largest-element-in-an-array/
-
-δҵ `k` Ԫءע⣬Ҫҵĵ `k` Ԫأǵ `k` ͬԪء
-
-ʾ 1:
-```c
-: [3,2,1,5,6,4] k = 2
-: 5
-```
-
-ʾ 2:
-```c
-: [3,2,3,1,2,4,5,5,6] k = 4
-: 4
-```
-
-˵:
-
-Լ `k` Чģ `1 k ij`
-
-
-
-
-
-**ο룺**
-
-˼·ķ
-
-- ״̬ͨ
-- ִʱ: 152 ms, C# ύл 76.47% û
-- ڴ: 24.6 MB, C# ύл 5.55% û
-
-```c
-public class Solution
-{
- public int FindKthLargest(int[] nums, int k)
- {
- nums = nums.OrderBy(a => a).ToArray();
- return nums[nums.Length - k];
- }
-}
-```
-
-
-
-
----
-## Ŀ08ij˻
-
-
-> - ţ238
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/product-of-array-except-self/
-
-Ϊ`n``nums``n > 1``output``output[i]` `nums`г`nums[i]`֮Ԫصij˻
-
-ʾ:
-```c
-: [1,2,3,4]
-: [24,12,8,6]
-```
-
-˵: 벻Ҫʹó`O(n)` ʱ临Ӷɴ⡣
-
-
-
-ڳռ临ӶĿ𣿣 ڶԿռ临ӶȷĿģ鲻Ϊռ䡣
-
-
-
-
-
-
-**ο룺**
-
-˼·˻ = ǰߵij˻ * ǰұߵij˻
-
-```c
- [1, 2, 3, 4]
- ߵij˻ [1, 1, 2, 6]
- ұߵij˻ [24,12,4, 1]
- = * [24,12,8, 6]
-```
-
-- ״̬ͨ
-- ִʱ: 304 ms, C# ύл 100.00% û
-- ڴ: 34.6 MB, C# ύл 100.00% û
-
-```c
-public class Solution
-{
- public int[] ProductExceptSelf(int[] nums)
- {
- int len = nums.Length;
- int[] output1 = new int[len];//˻
- int[] output2 = new int[len];//˻
- output1[0] = 1;
- output2[len - 1] = 1;
- for (int i = 1; i < len; i++)
- {
- output1[i] = output1[i - 1]*nums[i - 1];
- output2[len - i - 1] = output2[len - i]*nums[len - i];
- }
- for (int i = 0; i < len; i++)
- {
- output1[i] *= output2[i];
- }
- return output1;
- }
-}
-```
-
-
----
-## Ŀ09Ѱλ
-
-
-> - ţ4
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/median-of-two-sorted-arrays/
-
-СΪ`m``n``nums1``nums2`
-
-ҳλҪ㷨ʱ临ӶΪ`O(log(m + n))`
-
-Լ`nums1``nums2`ͬʱΪա
-
-ʾ 1:
-```c
-nums1 = [1, 3]
-nums2 = [2]
-
-λ 2.0
-```
-
-ʾ 2:
-
-```c
-nums1 = [1, 2]
-nums2 = [3, 4]
-
-λ (2 + 3)/2 = 2.5
-```
-
-**ο룺**
-
-˼·öֲԡ
-
-λһϻΪȵӼһӼеԪǴһӼеԪء
-
-ĿҪʱ临ӶΪ`O(log(m + n))`ԲܴβҵλӶ `O(m + n)`ҪֲͨԣͨÿαȽϣֱܹӰˢһ֣ҵλӶ`O(log(m + n))`
-
-```c
-nums1: [a1,a2,a3,...am]
-nums2: [b1,b2,b3,...bn]
-
-[nums1[:i],nums2[:j] | nums1[i:], nums2[j:]]
-
-nums1 ȡ i
-nums2 ȡ j = (m+n+1)/2 - i
-```
-ֻҪ֤ ͬλ `|` ߽Ա߲Ӷöַҵʵ`i`
-
-- ״̬ͨ
-- ִʱ: 160 ms, C# ύл 99.18% û
-- ڴ: 26.8 MB, C# ύл 5.05% û
-
-```c
-public class Solution {
- public double FindMedianSortedArrays(int[] nums1, int[] nums2) {
- int m = nums1.Length;
- int n = nums2.Length;
- if (m > n)
- return FindMedianSortedArrays(nums2, nums1);
-
- int k = (m + n + 1)/2;
- int left = 0;
- int right = m;
- while (left < right)
- {
- int i = (left + right)/2;
- int j = k - i;
- if (nums1[i] < nums2[j - 1])
- left = i + 1;
- else
- right = i;
- }
- int m1 = left;
- int m2 = k - left;
- int c1 = Math.Max(m1 == 0 ? int.MinValue : nums1[m1 - 1],
- m2 == 0 ? int.MinValue : nums2[m2 - 1]);
-
- if ((m + n)%2 == 1)
- return c1;
-
- int c2 = Math.Min(m1 == m ? int.MaxValue : nums1[m1],
- m2 == n ? int.MaxValue : nums2[m2]);
- return (c1 + c2)*0.5;
- }
-}
-```
-
----
-## Ŀ10ȱʧĵһ
-
-
-> - ţ41
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/first-missing-positive/
-
-һδ飬ҳûгֵС
-
-ʾ1:
-
-```c
-: [1,2,0]
-: 3
-```
-
-ʾ2:
-
-```c
-: [3,4,-1,1]
-: 2
-```
-
-ʾ3:
-```c
-: [7,8,9,11,12]
-: 1
-```
-
-ʾ4:
-```c
-: [1,1]
-: 2
-```
-
-ʵ5:
-
-```c
-: []
-: 1
-```
-
-˵:
-
-㷨ʱ临ӶӦΪO(n)ֻʹóĿռ䡣
-
-**ο룺**
-
-˼·һΡĹǣ`i`ڡ䷶Χ`i`Ӧ÷Ϊ`i - 1`λϡ
-
-- ִнͨ
-- ִʱ100 ms, C# ύл 93.75% û
-- ڴģ24.2 MB, C# ύл 97.44% û
-
-
-```c
-public class Solution {
- public int FirstMissingPositive(int[] nums) {
- int len = nums.Length;
- for (int i = 0; i < len; i++)
- {
- while (nums[i] != i + 1 && nums[i] <= len && nums[i] > 0 && nums[i] != nums[nums[i] - 1])
- {
- int temp = nums[i];
- nums[i] = nums[temp - 1];
- nums[temp - 1] = temp;
- }
- }
- for (int i = 0; i < len; i++)
- {
- if (nums[i] != i + 1)
- {
- return i + 1;
- }
- }
- return len + 1; //nums.Length = 0
- }
-}
-```
-
-
-
diff --git a/DataStructureAndAlgorithm/12 数组与稀疏矩阵.md b/DataStructureAndAlgorithm/05 数组与稀疏矩阵.md
similarity index 99%
rename from DataStructureAndAlgorithm/12 数组与稀疏矩阵.md
rename to DataStructureAndAlgorithm/05 数组与稀疏矩阵.md
index 590e8ac..4b6bfbb 100644
--- a/DataStructureAndAlgorithm/12 数组与稀疏矩阵.md
+++ b/DataStructureAndAlgorithm/05 数组与稀疏矩阵.md
@@ -1,4 +1,4 @@
-# 12 ϡ
+# 05 ϡ
**֪ʶṹ**
diff --git a/DataStructureAndAlgorithm/13 字符串与整数集合.md b/DataStructureAndAlgorithm/06 字符串与整数集合.md
similarity index 99%
rename from DataStructureAndAlgorithm/13 字符串与整数集合.md
rename to DataStructureAndAlgorithm/06 字符串与整数集合.md
index 608ff97..5365050 100644
--- a/DataStructureAndAlgorithm/13 字符串与整数集合.md
+++ b/DataStructureAndAlgorithm/06 字符串与整数集合.md
@@ -1,4 +1,4 @@
-# 13 ַ
+# 06 ַ
**֪ʶ㣺**
diff --git a/DataStructureAndAlgorithm/07 Leetcode同步练习(二).md b/DataStructureAndAlgorithm/07 Leetcode同步练习(二).md
deleted file mode 100644
index 91b09a6..0000000
--- a/DataStructureAndAlgorithm/07 Leetcode同步练习(二).md
+++ /dev/null
@@ -1,759 +0,0 @@
-
-# Leetcodeͬϰ
-
-## Ŀ01
-
-> - ţ9
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/palindrome-number/
-
-жһǷǻָң͵һ
-
-ʾ 1:
-```c
-: 121
-: true
-```
-
-ʾ 2:
-
-```c
-: -121
-: false
-: Ҷ, Ϊ -121 , Ϊ 121- һ
-```
-
-ʾ 3:
-```c
-: 10
-: false
-: , Ϊ 01 һ
-```
-
-**д**
-
-```c
-public class Solution
-{
- public bool IsPalindrome(int x)
- {
-
- }
-}
-```
-
-:
-
-ܲתΪַ
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 76 ms, C# ύл 98.90% û
-- ڴ: 14.9 MB, C# ύл 85.12% û
-
-```c
-public class Solution {
- public bool IsPalindrome(int x) {
- if (x < 0)
- return false;
-
- int bit = 1;
- while (x / bit >= 10)
- {
- bit = bit * 10;
- }
-
- while (x > 0)
- {
- int left = x % 10;
- int right = x / bit;
- if (left != right)
- {
- return false;
- }
- x = (x % bit) / 10;
- bit = bit / 100;
- }
- return true;
-}
-```
-
-
-
----
-## Ŀ02x ƽ
-
-> - ţ69
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/sqrtx/
-
-ʵ `int sqrt(int x)`
-
-㲢`x`ƽ`x`ǷǸ
-
-ڷֻIJ֣Сֽȥ
-
-ʾ 1:
-
-```c
-: 4
-: 2
-```
-
-ʾ 2:
-
-```c
-: 8
-: 2
-˵: 8 ƽ 2.82842..., ڷСֽȥ
-```
-
-**˼·**ţٵ
-
-
-
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 48 ms, C# ύл 100.00% û
-- ڴ: 13.7 MB, C# ύл 5.40% û
-
-```c
-public class Solution {
- public int MySqrt(int x) {
- if (x < 0)
- throw new ArgumentOutOfRangeException();
-
- double error = 1.0e-5;
- double cur = x;
- while (Math.Abs(cur*cur - x) > error)
- {
- cur = (cur + 1.0*x/cur)/2.0;
- }
- return (int)cur;
- }
-}
-```
-
-
----
-## Ŀ03¥
-
-> - ţ70
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/climbing-stairs/
-
-¥ݡҪ n ܵ¥
-
-ÿ 1 2 ̨סжֲͬķ¥أ
-
-ע n һ
-
-ʾ 1
-```c
-룺 2
- 2
-ͣ ַ¥
-1. 1 + 1
-2. 2
-```
-
-ʾ 2
-```c
-룺 3
- 3
-ͣ ַ¥
-1. 1 + 1 + 1
-2. 1 + 2
-3. 2 + 1
-```
-
-ʾ 3
-```c
-룺 44
- 1134903170
-```
-
-**˼·**ѭ
-
-Ŀ
-- 1 ףf(1) = 1 ַ
-- 2 ףf(2) = 2 ַ
-- 3 ףf(3) = 3 ַ
-- 4 ףf(4) = 5 ַ
--
-- n ףf(n) = f(n-1) + f(n-2) ַ
-
-תΪ쳲⡣
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 52 ms, C# ύл 97.87% û
-- ڴ: 13.7 MB, C# ύл 5.98% û
-
-```c
-public class Solution {
- public int ClimbStairs(int n) {
- if (n <= 2)
- return n;
-
- int first = 1;
- int second = 2;
- int result = 0;
-
- for (int i = 3; i <= n; i++)
- {
- result = first + second;
- first = second;
- second = result;
- }
- return result;
- }
-}
-```
-
----
-## Ŀ04Ʊʱ
-
-> - ţ121
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/
-
-һ飬ĵ i Ԫһ֧Ʊ i ļ۸
-
-ֻһʽףһ֧Ʊһ㷨ܻȡ
-
-ע㲻ƱǰƱ
-
-ʾ 1:
-```c
-: [7,1,5,3,6,4]
-: 5
-: ڵ 2 죨Ʊ۸ = 1ʱ룬ڵ 5 죨Ʊ۸ = 6ʱ = 6-1 = 5
- ע 7-1 = 6, Ϊ۸Ҫ۸
-```
-
-ʾ 2:
-```c
-: [7,6,4,3,1]
-: 0
-: , ûн, Ϊ 0
-```
-
-**˼·**ѹƱܹǮֵΪ
-
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 132 ms, C# ύл 97.33% û
-- ڴ: 24 MB, C# ύл 5.62% û
-
-```c
-public class Solution
-{
- public int MaxProfit(int[] prices)
- {
- if (prices.Length <= 1)
- return 0;
-
- int min = prices[0];
- int max = 0;
- for (int i = 1; i < prices.Length; i++)
- {
- int earn = prices[i] - min;
- if (earn > max)
- {
- max = earn;
- }
- if (prices[i] < min)
- {
- min = prices[i];
- }
- }
- return max;
- }
-}
-```
-
-
----
-## Ŀ05Ʊʱ II
-
-> - ţ122
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/
-
-
-һ飬ĵ i Ԫһ֧Ʊ i ļ۸
-
-һ㷨ܻȡԾܵɸĽףһ֧Ʊ
-
-ע㲻ͬʱʽףٴιǰ۵֮ǰĹƱ
-
-ʾ 1:
-```c
-: [7,1,5,3,6,4]
-: 7
-:
- ڵ 2 죨Ʊ۸ = 1ʱ룬ڵ 3 죨Ʊ۸ = 5ʱ, ʽܻ = 5-1 = 4
- ڵ 4 죨Ʊ۸ = 3ʱ룬ڵ 5 죨Ʊ۸ = 6ʱ, ʽܻ = 6-3 = 3
-```
-
-ʾ 2:
-```c
-: [1,2,3,4,5]
-: 4
-:
- ڵ 1 죨Ʊ۸ = 1ʱ룬ڵ 5 Ʊ۸ = 5ʱ, ʽܻ = 5-1 = 4
- ע㲻ڵ 1 ͵ 2 Ʊ֮ٽ
- Ϊͬʱ˶ʽףٴιǰ۵֮ǰĹƱ
-```
-
-ʾ 3:
-```c
-: [7,6,4,3,1]
-: 0
-: , ûн, Ϊ 0
-```
-
-**˼·**̰㷨
-
-̰IJԣֻҪһ۸ǰһߣǰһһ
-
-
-
-
-
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 140 ms, C# ύл 72.02% û
-- ڴ: 24.2 MB, C# ύл 5.36% û
-
-
-```c
-public class Solution
-{
- public int MaxProfit(int[] prices)
- {
- int earn = 0;
- for (int i = 0; i < prices.Length-1; i++)
- {
- earn += Math.Max(prices[i + 1] - prices[i], 0);
- }
- return earn;
- }
-}
-```
-
-
----
-## Ŀ06ԾϷ
-
-> - ţ55
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/jump-game/
-
-һǸ飬λĵһλá
-
-еÿԪشڸλÿԾȡ
-
-жǷܹһλá
-
-**ʾ 1:**
-
-```c
-: [2,3,1,1,4]
-: true
-: ǿ 1 λ 0 λ 1, Ȼٴλ 1 3
-һλá
-```
-
-**ʾ 2:**
-
-```c
-: [3,2,1,0,4]
-: false
-: ܻᵽΪ 3 λáλõԾ 0
-Զܵһλá
-```
-
-**ʾ 3:**
-
-```c
-룺[0]
-true
-```
-
-**˼·̰㷨**
-
-̰IJԣÿμ¼ֵǰ㳬ֵfalseֵﵽһλãtrue
-
-**ο룺**
-
-- ִнͨ
-- ִʱ120 ms, C# ύл 57.32% û
-- ڴģ26.2 MB, C# ύл 6.67% û
-
-```c
-public class Solution
-{
- public bool CanJump(int[] nums)
- {
- int maxlength = 0; //¼ܵԶ
- for (int i = 0; maxlength < nums.Length-1; i++)
- {
- if (i > maxlength)
- {
- return false;//˵Ѳܵfalse
- }
- maxlength = Math.Max(i + nums[i], maxlength);
- }
- return true;
- }
-}
-```
-
-
-
-
-
----
-## Ŀ07֮
-
-> - ţ15
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/3sum/
-
-һ`n``nums`ж`nums`ǷԪ`abc`ʹ`a + b + c = 0`ҳҲظԪ顣
-
-ע⣺вظԪ顣
-
-**ʾ**
-
-```c
- nums = [-1, 0, 1, 2, -1, -4]
-
-ҪԪ鼯Ϊ
-[
- [-1, 0, 1],
- [-1, -1, 2]
-]
-```
-
-
-
-**˼· + ķ**
-
-Ϊ˱ѭִЧʡȣ`nums`Ȼ̶3`i,l(left),r(right)``i`ѭ`l`ָ`nums[i]`֮Сֵ`r`ָ`nums[i]`ֵ֮ģ¿˼·`nums[i] > 0`ͲҪˣ`nums[i] + nums[l] + nums[r]`Ƿ㲢ӦĴ㣬`l`ƶ`r`ָ룬С㣬`r`ƶ`l`㣬뵽洢resultСȻĿҪԪ鲻ظڽеĹмȥؾͺá
-
-**ο룺**
-
-- ִнͨ
-- ִʱ348 ms, C# ύл 99.54% û
-- ڴģ35.8 MB, C# ύл 6.63% û
-
-```c
-public class Solution
-{
- public IList> ThreeSum(int[] nums)
- {
- IList> result = new List>();
-
- nums = nums.OrderBy(a => a).ToArray();
- int len = nums.Length;
-
- for (int i = 0; i < len - 2; i++)
- {
- if (nums[i] > 0)
- break; // Сִ0, IJѾû
-
- if (i > 0 && nums[i - 1] == nums[i])
- continue; // ԪеһԪصظ
-
- int l = i + 1;
- int r = len - 1;
-
- while (l < r)
- {
- int sum = nums[i] + nums[l] + nums[r];
- if (sum < 0)
- {
- l++;
- }
- else if (sum > 0)
- {
- r--;
- }
- else
- {
- result.Add(new List() {nums[i], nums[l], nums[r]});
- // ԪеڶԪصظ
- while (l < r && nums[l] == nums[l + 1])
- {
- l++;
- }
- // ԪеԪصظ
- while (l < r && nums[r - 1] == nums[r])
- {
- r--;
- }
- l++;
- r--;
- }
- }
- }
- return result;
- }
-}
-```
-
-
----
-## Ŀ08ӽ֮
-
-> - ţ16
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/3sum-closest/
-
-һ`n``nums`һĿֵ`target`ҳ`nums`еʹǵĺ`target`ӽĺ͡ٶÿֻΨһ𰸡
-
-ʾ :
-
-```c
-磬 nums = [-121-4], target = 1.
- target ӽĺΪ 2. (-1 + 2 + 1 = 2).
-```
-
-
-˼· + ķ
-
-
-**ο룺**
-
-- ״̬ͨ
-- ִʱ: 132 ms, C# ύл 100.00% û
-- ڴ: 24 MB, C# ύл 5.55% û
-
-
-```c
-public class Solution
-{
- public int ThreeSumClosest(int[] nums, int target)
- {
- nums = nums.OrderBy(a => a).ToArray();
- int result = nums[0] + nums[1] + nums[2];
- for (int i = 0; i < nums.Length - 2; i++)
- {
- int start = i + 1, end = nums.Length - 1;
- while (start < end)
- {
- int sum = nums[start] + nums[end] + nums[i];
- if (Math.Abs(target - sum) < Math.Abs(target - result))
- result = sum;
- if (sum > target)
- end--;
- else if (sum < target)
- start++;
- else
- return result;
- }
- }
- return result;
- }
-}
-```
-
----
-## Ŀ09 II
-
-> - ţ59
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/spiral-matrix-ii/
-
-һ nһ 1 n^2 ԪأԪذ˳ʱ˳еξ
-
-ʾ:
-```c
-: 3
-:
-[
- [ 1, 2, 3 ],
- [ 8, 9, 4 ],
- [ 7, 6, 5 ]
-]
-```
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 296 ms, C# ύл 97.67% û
-- ڴ: 25 MB, C# ύл 11.11% û
-
-```c
-public class Solution
-{
- public int[][] GenerateMatrix(int n)
- {
- int[][] matrix = new int[n][];
- for (int i = 0; i < n; i++)
- {
- matrix[i] = new int[n];
- }
-
- int start = 0;//ʼλ
- int end1 = n - 1;//λ
- int end2 = n - 1;//±λ
- int count = 1;
-
- while (start < end1 && start < end2)
- {
- LeftToRight(start, end1, start, matrix, ref count);
- TopToBottom(start + 1, end2, end1, matrix, ref count);
- RightToLeft(end1 - 1, start, end2, matrix, ref count);
- BottomToTop(end2 - 1, start + 1, start, matrix, ref count);
- start++;
- end1 = n - 1 - start;
- end2 = n - 1 - start;
- }
- if (n%2 == 1)
- {
- matrix[start][start] = count;
- }
- return matrix;
- }
-
- private void LeftToRight(int start, int end, int rowIndex, int[][] matrix, ref int from)
- {
- for (int i = start; i <= end; i++)
- {
- matrix[rowIndex][i] = from;
- from++;
- }
- }
-
- private void TopToBottom(int start, int end, int colIndex, int[][] matrix, ref int from)
- {
- for (int i = start; i <= end; i++)
- {
- matrix[i][colIndex] = from;
- from++;
- }
- }
-
- private void RightToLeft(int start, int end, int rowIndex, int[][] matrix, ref int from)
- {
- for (int i = start; i >= end; i--)
- {
- matrix[rowIndex][i] = from;
- from++;
- }
- }
-
- private void BottomToTop(int start, int end, int colIndex, int[][] matrix, ref int from)
- {
- for (int i = start; i >= end; i--)
- {
- matrix[i][colIndex] = from;
- from++;
- }
- }
-}
-```
-
-
-
-## Ŀ10ͬ·
-
-> - ţ62
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/unique-paths/
-
-һλһ m x n Ͻ ʼͼбΪStart
-
-ÿֻ»ƶһͼﵽ½ǣͼбΪFinish
-
-ܹжͬ·
-
-
-
-磬ͼһ7 x 3 жٿܵ·
-
-˵m n ֵ 100
-
-ʾ 1:
-```c
-: m = 3, n = 2
-: 3
-:
-Ͻǿʼܹ 3 ·Ե½ǡ
-1. -> ->
-2. -> ->
-3. -> ->
-```
-
-ʾ 2:
-```c
-: m = 7, n = 3
-: 28
-```
-
-ʾ 3:
-```c
-: m = 23, n = 12
-: 193536720
-```
-
-˼·ö̬滮
-
-̬滮01
-
-
-
-̬滮02
-
-
-
-̬滮ӽṹΪ`d[i,j] = d[i-1,j] + d[i,j-1]`
-
-- ״̬ͨ
-- 62 / 62 ͨ
-- ִʱ: 52 ms, C# ύл 93.18% û
-- ڴ: 13.6 MB, C# ύл 17.65% û
-
-```c
-public class Solution
-{
- public int UniquePaths(int m, int n)
- {
- int[,] memo = new int[m, n];
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (i == 0)
- {
- memo[i, j] = 1;
- }
- else if (j == 0)
- {
- memo[i, j] = 1;
- }
- else
- {
- memo[i, j] = memo[i - 1, j] + memo[i, j - 1];
- }
- }
- }
- return memo[m - 1, n - 1];
- }
-}
-```
-
-
-
diff --git a/DataStructureAndAlgorithm/15 树.md b/DataStructureAndAlgorithm/07 树.md
similarity index 99%
rename from DataStructureAndAlgorithm/15 树.md
rename to DataStructureAndAlgorithm/07 树.md
index 6c936b4..38f476f 100644
--- a/DataStructureAndAlgorithm/15 树.md
+++ b/DataStructureAndAlgorithm/07 树.md
@@ -1,5 +1,5 @@
-# 15
+# 07
**֪ʶṹ**
diff --git a/DataStructureAndAlgorithm/08 Leetcode同步练习(三).md b/DataStructureAndAlgorithm/08 Leetcode同步练习(三).md
deleted file mode 100644
index 11215b2..0000000
--- a/DataStructureAndAlgorithm/08 Leetcode同步练习(三).md
+++ /dev/null
@@ -1,794 +0,0 @@
-
-# Leetcodeͬϰ
-
-
-## Ŀ01ϲ
-
-> - ţ21
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/merge-two-sorted-lists/
-
-ϲΪһµءͨƴӸнڵɵġ
-
-**ʾ**
-
-```c
-룺1->2->4, 1->3->4
-1->1->2->3->4->4
-```
-
-**ο**
-
-- ִнͨ
-- ִʱ108 ms, C# ύл 83.80% û
-- ڴģ25.9 MB, C# ύл 5.85% û
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public ListNode MergeTwoLists(ListNode l1, ListNode l2)
- {
- ListNode pHead = new ListNode(int.MaxValue);
- ListNode temp = pHead;
-
- while (l1 != null && l2 != null)
- {
- if (l1.val < l2.val)
- {
- temp.next = l1;
- l1 = l1.next;
- }
- else
- {
- temp.next = l2;
- l2 = l2.next;
- }
- temp = temp.next;
- }
-
- if (l1 != null)
- temp.next = l1;
-
- if (l2 != null)
- temp.next = l2;
-
- return pHead.next;
- }
-}
-```
-
----
-## Ŀ02ɾеظԪ
-
-> - ţ83
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/
-
-
-һɾظԪأʹÿԪֻһΡ
-
-
-**ʾ 1:**
-
-```c
-: 1->1->2
-: 1->2
-```
-
-**ʾ 2:**
-```c
-: 1->1->2->3->3
-: 1->2->3
-```
-
-**˼·**˫ָķʽ
-
-`p1`Ϊǰָ̽·`p2`ΪָظԪأ`p2.next`ȥ`p1`ظԪضժ
-
-**ο**
-
-- ִнͨ
-- ִʱ160 ms, C# ύл 5.23% û
-- ڴģ25.9 MB, C# ύл 5.72% û
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-
-public class Solution
-{
- public ListNode DeleteDuplicates(ListNode head)
- {
- if (head == null)
- return head;
-
- ListNode p1 = head.next;
- ListNode p2 = head;
- while (p1 != null)
- {
- if (p1.val == p2.val)
- p2.next = p1.next;
- else
- p2 = p2.next;
- p1 = p1.next;
- }
- return head;
- }
-}
-```
-
----
-## Ŀ03
-
-> - ţ141
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/linked-list-cycle/
-
-һжǷл
-
-Ϊ˱ʾеĻʹ`pos` ʾβӵеλã 0 ʼ `pos` -1ڸûл
-
-ʾ 1
-```c
-룺head = [3,2,0,-4], pos = 1
-true
-ͣһβӵڶڵ㡣
-```
-
-
-
-ʾ 2
-```c
-룺head = [1,2], pos = 0
-true
-ͣһβӵһڵ㡣
-```
-
-
-ʾ 3
-```c
-룺head = [1], pos = -1
-false
-ͣûл
-```
-
-
-
-
- O(1)ڴ
-
-**˼·**˫ָķʽ
-
-ͨ£жǷظԪأʹ`Hash`ķʽڵֳҲʹ˫ָķʽ
-
-һָ `p1` ÿƶڵ㣬ڶָ `p2` ÿƶһڵ㣬ڻĻһָһٴڶָ룬֮ڻ
-
-磺`head = [1,2,3,4,5]`
-
-```c
-p11 3 5 2 4 1
-p21 2 3 4 5 1
-```
-
-磺`head = [1,2,3,4]`ż
-```c
-p11 3 1 3 1
-p21 2 3 4 1
-```
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 112 ms, C# ύл 98.43% û
-- ڴ: 24.9 MB, C# ύл 5.13% û
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) {
- * val = x;
- * next = null;
- * }
- * }
- */
-public class Solution {
- public bool HasCycle(ListNode head) {
- ListNode p1 = head;
- ListNode p2 = head;
-
- while (p1 != null && p1.next != null)
- {
- p1 = p1.next.next;
- p2 = p2.next;
- if (p1 == p2)
- return true;
- }
- return false;
- }
-}
-```
-
-## Ŀ04ת
-
-
-> - ţ206
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/reverse-linked-list/
-
-תһ
-
-ʾ:
-```c
-: 1->2->3->4->5->NULL
-: 5->4->3->2->1->NULL
-```
-
-:
-
-Եݹطתַܷ⣿
-
-**˼·**˫ָķʽ
-
-`p1`Ϊǰָ̽·`p2`Ϊָ˳һȦ㶨⡣
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 116 ms, C# ύл 97.50% û
-- ڴ: 23.3 MB, C# ύл 5.26% û
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-
-public class Solution
-{
- public ListNode ReverseList(ListNode head)
- {
- if (head == null || head.next == null)
- return head;
-
- ListNode p1 = head;
- ListNode p2 = null;
- while (p1 != null)
- {
- ListNode temp = p1.next;
- p1.next = p2;
- p2 = p1;
- p1 = temp;
- }
- return p2;
- }
-}
-```
-
----
-## Ŀ05ɾеĽڵ
-
-> - ţ237
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/delete-node-in-a-linked-list/
-
-дһʹɾijиģĩβڵ㣬㽫ֻҪɾĽڵ㡣
-
-һ -- head = [4,5,1,9]ԱʾΪ:
-
-
-
-
-ʾ 1:
-```c
-: head = [4,5,1,9], node = 5
-: [4,1,9]
-: ֵΪ 5 ĵڶڵ㣬ôڵĺ֮ӦΪ 4 -> 1 -> 9.
-```
-
-ʾ 2:
-```c
-: head = [4,5,1,9], node = 1
-: [4,5,9]
-: ֵΪ 1 ĵڵ㣬ôڵĺ֮ӦΪ 4 -> 5 -> 9.
-```
-
-˵:
-
-- ٰڵ㡣
-- нڵֵΨһġ
-- ĽڵΪĩβڵ㲢һеһЧڵ㡣
-- Ҫĺзκν
-
-
-
-**˼·** ûиͷڵ㣬ֱӸҪɾĽڵ㣬ǽԭɾǶڸýڵǰһڵһֱִ֪ɾˣǽҪɾڵ next ڵֵֵҪɾĽڵ㣬תȥɾ next ڵ㣬ӶĿġ
-
-**ο**
-
-- ״̬ͨ
-- 41 / 41 ͨ
-- ִʱ: 120 ms, C# ύл 99.55% û
-- ڴ: 24.4 MB, C# ύл 5.88% û
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-
-public class Solution
-{
- public void DeleteNode(ListNode node)
- {
- ListNode temp = node.next;
- while (temp != null)
- {
- node.val = temp.val;
- temp = temp.next;
- if (temp != null)
- {
- node = node.next;
- }
- }
- node.next = null;
- }
-}
-```
-
-
-
----
-## Ŀ06
-
-> - ţ2
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/add-two-numbers/
-
- ǿ ʾǸУǸԵλǰ ķʽ洢ģǵÿڵֻܴ洢 һλ ֡
-
-ǽ᷵һµʾǵĺ͡
-
-Լ 0 ֮⣬ 0 ͷ
-
-ʾ 1
-```c
-룺(2 -> 4 -> 3) + (5 -> 6 -> 4)
-7 -> 0 -> 8
-ԭ342 + 465 = 807
-```
-
-ʾ 2
-```c
-룺(3 -> 7) + (9 -> 2)
-2 -> 0 -> 1
-ԭ73 + 29 = 102
-```
-
-**˼·**ģСѧʱѧļӷ㡣λӳʮһʮλнλϽλơ
-
-ο룺
-
-- ״̬ͨ
-- ִʱ: 144 ms, C# ύл 97.98% û
-- ڴ: 26.7 MB, C# ύл 5.07% û
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public ListNode AddTwoNumbers(ListNode l1, ListNode l2)
- {
- ListNode result = new ListNode(-1);
- ListNode l3 = result;
- int flag = 0;
- while (l1 != null && l2 != null)
- {
- int a = l1.val;
- int b = l2.val;
- int c = a + b + flag;
- l3.next = new ListNode(c%10);
-
- flag = c >= 10 ? 1 : 0;
- l1 = l1.next;
- l2 = l2.next;
- l3 = l3.next;
- }
-
- while (l1 != null)
- {
- int a = l1.val + flag;
-
- l3.next = new ListNode(a%10);
-
- flag = a >= 10 ? 1 : 0;
- l1 = l1.next;
- l3 = l3.next;
- }
-
- while (l2 != null)
- {
- int b = l2.val + flag;
-
- l3.next = new ListNode(b%10);
- flag = b >= 10 ? 1 : 0;
- l2 = l2.next;
- l3 = l3.next;
- }
-
- if (flag == 1)
- {
- l3.next = new ListNode(flag);
- }
- return result.next;
- }
-}
-```
-
----
-## Ŀ07ɾĵNڵ
-
-> - ţ19
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/
-
-һɾĵ`n`ڵ㣬ҷͷ㡣
-
-**ʾ**
-
-```c
-һ: 1->2->3->4->5, n = 2.
-
-ɾ˵ڶڵΪ 1->2->3->5.
-```
-
-**˵**
-
-`n`֤Чġ
-
-****
-
-ܳʹһɨʵ
-
-**˼·** ʹָ룬ǰָ`p1``n`úָ`p2``p1`ͬߣ`p1`ߵյ㣬`p2`ߵҪƳĽλá
-
-**ο룺**
-- ִнͨ
-- ִʱ104 ms, C# ύл 86.93% û
-- ڴģ24.6 MB, C# ύл 100.00% û
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public ListNode RemoveNthFromEnd(ListNode head, int n)
- {
- ListNode p1 = head;
- ListNode p2 = head;
-
- while (n > 0)
- {
- p1 = p1.next;
- n--;
- }
-
- if (p1 == null) //Ƴͷ
- {
- return head.next;
- }
-
- while (p1.next != null)
- {
- p1 = p1.next;
- p2 = p2.next;
- }
-
- p2.next = p2.next.next;
- return head;
- }
-}
-```
-
-
----
-## Ŀ08еĽڵ
-
-> - ţ24
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/swap-nodes-in-pairs/
-
-һڵĽڵ㣬ؽ
-
-**㲻ֻǵĸıڵڲֵ**ҪʵʵĽнڵ㽻
-
-
-
-**ʾ:**
-
-> 1->2->3->4, Ӧ÷ 2->1->4->3.
-
-
-**ο**
-
-- ִнͨ
-- ִʱ100 ms, C# ύл 93.18% û
-- ڴģ23.4 MB, C# ύл 87.72% û
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-
-public class Solution
-{
- public ListNode SwapPairs(ListNode head)
- {
- if (head == null || head.next == null)
- return head;
-
- head = Swap(head);
-
- ListNode temp = head.next;
-
- while (temp != null && temp.next != null)
- {
- temp.next = Swap(temp.next);
- if (temp.next != null)
- {
- temp = temp.next.next;
- }
- }
- return head;
- }
-
- public ListNode Swap(ListNode node)
- {
- if (node == null || node.next == null)
- return node;
-
- ListNode t = node.next;
- node.next = t.next;
- t.next = node;
- return t;
- }
-}
-```
-
----
-## Ŀ09ת
-
-
-> - ţ61
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/rotate-list/
-
-һתÿڵƶ k λã k ǷǸ
-
-**ʾ 1:**
-
-```c
-: 1->2->3->4->5->NULL, k = 2
-: 4->5->1->2->3->NULL
-
-:
-ת 1 : 5->1->2->3->4->NULL
-ת 2 : 4->5->1->2->3->NULL
-```
-
-**ʾ 2:**
-
-```c
-: 0->1->2->NULL, k = 4
-: 2->0->1->NULL
-
-:
-ת 1 : 2->0->1->NULL
-ת 2 : 1->2->0->NULL
-ת 3 : 0->1->2->NULL
-ת 4 : 2->0->1->NULL
-```
-
-
-
-
-**ο**
-
-- ִнͨ
-- ִʱ100 ms, C# ύл 98.13% û
-- ڴģ25.1 MB, C# ύл 100.00% û
-
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-
-public class Solution
-{
- public ListNode RotateRight(ListNode head, int k)
- {
- if (head == null || k == 0)
- return head;
-
- int len = GetLength(head);
- int index = len - k%len;
-
- if (index == len)
- return head;
-
- ListNode temp1 = head;
- ListNode temp2 = head;
- for (int i = 0; i < index - 1; i++)
- {
- temp1 = temp1.next;
- }
- head = temp1.next;
- temp1.next = null;
-
- temp1 = head;
- while (temp1.next != null)
- {
- temp1 = temp1.next;
- }
- temp1.next = temp2;
- return head;
- }
-
- public int GetLength(ListNode head)
- {
- ListNode temp = head;
- int i = 0;
- while (temp != null)
- {
- i++;
- temp = temp.next;
- }
- return i;
- }
-}
-```
-
-
-
----
-## Ŀ10ϲK
-
-> - ţ23
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/merge-k-sorted-lists/
-
-
-ϲ k غϲ㷨ĸӶȡ
-
-ʾ:
-```c
-:
-[
- 1->4->5,
- 1->3->4,
- 2->6
-]
-: 1->1->2->3->4->4->5->6
-```
-
-˼·ϲķʽ
-
-ϲõһµķ`ListNode MergeTwoLists(ListNode l1, ListNode l2)`ʹø÷ϲǰõһµ֮ϲƣõϲ`K`бб
-
-
-**ο**
-
-- ִнͨ
-- ִʱ256 ms, C# ύл 36.69% û
-- ڴģ29.3 MB, C# ύл 18.37% û
-
-
-```c
-/**
- * Definition for singly-linked list.
- * public class ListNode {
- * public int val;
- * public ListNode next;
- * public ListNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public ListNode MergeTwoLists(ListNode l1, ListNode l2)
- {
- ListNode pHead = new ListNode(int.MaxValue);
- ListNode temp = pHead;
-
- while (l1 != null && l2 != null)
- {
- if (l1.val < l2.val)
- {
- temp.next = l1;
- l1 = l1.next;
- }
- else
- {
- temp.next = l2;
- l2 = l2.next;
- }
- temp = temp.next;
- }
-
- if (l1 != null)
- temp.next = l1;
-
- if (l2 != null)
- temp.next = l2;
-
- return pHead.next;
- }
-
- public ListNode MergeKLists(ListNode[] lists) {
- if (lists.Length == 0)
- return null;
-
- ListNode result = lists[0];
- for (int i = 1; i < lists.Length; i++)
- {
- result = MergeTwoLists(result, lists[i]);
- }
- return result;
- }
-}
-```
-
-
-
-
-
-
-
-
diff --git a/DataStructureAndAlgorithm/17 图.md b/DataStructureAndAlgorithm/08 图.md
similarity index 99%
rename from DataStructureAndAlgorithm/17 图.md
rename to DataStructureAndAlgorithm/08 图.md
index 4fa76e6..6cf9437 100644
--- a/DataStructureAndAlgorithm/17 图.md
+++ b/DataStructureAndAlgorithm/08 图.md
@@ -1,5 +1,5 @@
-# 17 ͼ
+# 08 ͼ
**֪ʶṹ**
diff --git a/DataStructureAndAlgorithm/09 排序.md b/DataStructureAndAlgorithm/09 排序.md
new file mode 100644
index 0000000..66673ef
--- /dev/null
+++ b/DataStructureAndAlgorithm/09 排序.md
@@ -0,0 +1,679 @@
+# 09 排序
+
+**知识结构:**
+
+
+
+
+
+## 1. 排序的基本概念与术语
+
+假设含有$n$个记录的序列为$\lbrace r_1,r_2,\cdots,r_n \rbrace$,其相应的关键字分别为$\lbrace k_1,k_2,\cdots,k_n \rbrace$,需确定 的一种排列$1,2,\cdots,n$,使其相应的关键字满足$k_{p_1}\leq k_{p_2}\leq\cdots\leq k_{p_n}$的关系,即使得序列成为一个按关键字有序的序列 ,这个样的操作就称为 **排列**。
+
+
+能唯一标识某一记录的关键字称为 **主关键字**。
+
+假设$k_i = k_j(1\leq i \leq n, 1\leq j\leq n,i\neq j)$,且在排序前的序列中$r_i$领先于$r_j$(即$i
+/// 直接插入排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void StraightInsertSort(T[] array) where T : IComparable
+{
+ for (int i = 1; i < array.Length; i++)
+ {
+ int j = i - 1;
+ T current = array[i];
+
+ while (j >= 0 && array[j].CompareTo(current) > 0)
+ {
+ array[j + 1] = array[j];
+ j--;
+ }
+ array[j + 1] = current;
+ }
+}
+```
+
+如果碰见一个和插入元素相等的,那么插入元素把想插入的元素放在相等元素的后面,所以,相等元素的前后顺序没有改变,从原无序序列出去的顺序就是排好序后的顺序,所以直接插入排序是稳定的。
+
+### 2.2 希尔插入排序
+
+希尔排序是1959年由D.L.Shell提出来的,相对直接插入排序有较大的改进。希尔插入排序又叫做**缩小增量排序**。
+
+直接插入排序的效率在某些时候是很高的,比如我们的记录本身就是基本有序的,我们只需要少量的插入操作,就可以完成整个记录集的排序工作,此时直接插入排序很高效。还有就是记录数比较少时,直接插入的优势也比较明显。可问题在于,两个条件本身就过于苛刻,现实中记录少或者基本有序都属于特殊情况。
+
+不过别着急,有条件当然是好,条件不存在,我们创造条件也是可以去做的。于是科学家希尔研究出了一种排序方法,对直接插入排序改进后可以增加效率。
+
+思想:按待排序列下标的一定增量分组(如:增量序列$t_1,t_2,\cdots,t_k$,其中$t_i>t_j$,$t_k=1$),将整个待排序列分割成若干子序列,分别进行直接插入排序,随着增量逐渐减少,所分组包含的记录越来越多,到增量值减至1时,整个记录集被分成一组(这时待排序列“基本有序”),再对全体记录进行直接插入排序,算法终止(对待排序列进行了$k$趟直接插入排序)。
+
+> 我所理解Shell Insertion Sort最牛的地方是,让排序算法能够并行化。
+
+希尔插入排序增量的取法:
+
+$delta1=\left[\frac{n}{2}\right] =\left[\frac{10}{2}\right]=5$
+
+$delta2=\left[\frac{delta1}{2}\right]=\left[\frac{5}{2}\right]=2$
+
+$delta3=\left[\frac{delta2}{2}\right]=\left[\frac{2}{2}\right]=1$
+
+即:先将要排序的一组记录按某个增量$delta$($\left[\frac{n}{2}\right]$ ,$n$为要排序数的个数)分成若干组子序列,每组中记录的下标相差$delta$。对每组中全部元素进行直接插入排序,然后在用一个较小的增量($\left[\frac{delta}{2}\right]$ )对它进行分组,在每组中再进行直接插入排序。继续不断缩小增量直至为1,最后使用直接插入排序完成排序。
+
+如:`int[] Key = new int[]{45,34,78,12,34,32,29,64};`
+
+排序过程:
+
+$d=4\rightarrow 45,\overline{34},78,12,34,32,29,64$
+
+$d=2\rightarrow 34,32,29,12,45,\overline{34},78,64$
+
+$d=1\rightarrow 29,12,34,32,45,\overline{34},78,64$
+
+$result\rightarrow 12,29,32,34,\overline{34},45,64,78$
+
+程序代码:
+```c
+private static void Shell(int delta, T[] array) where T : IComparable
+{
+ //带增量的直接插入排序
+ for (int i = delta; i < array.Length; i++)
+ {
+ int j = i - delta;
+ T current = array[i];
+ while (j >= 0 && array[j].CompareTo(current) > 0)
+ {
+ array[j + delta] = array[j];
+ j = j - delta;
+ }
+ array[j + delta] = current;
+ }
+}
+
+///
+/// 希尔插入排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void ShellInsertSort(T[] array) where T : IComparable
+{
+ for (int delta = array.Length/2; delta > 0; delta = delta/2)
+ {
+ Shell(delta, array);
+ }
+}
+```
+
+希尔插入排序时效分析很难,关键码的比较次数与记录移动次数依赖于增量因子序列$delta$的选取。目前还没有人给出选取最好的增量因子序列的方法。希尔插入排序方法是一个不稳定的排序方法。
+
+## 3. 选择排序
+
+### 3.1 直接选择排序
+
+思想:每一趟在$n-i(i=0,1,\cdots,n-1)$个记录中选取关键字最小的记录作为有序序列中第$i$个记录。(在要排列的一组数中,选出最小的一个数与第1个位置的数交换;然后在剩下的数当中再找最小的与第2个位置的数交换,依次类推,直到第$n-1$个元素和第$n$个元素比较为止。)
+
+如:`int[] Key = new int[]{45,34,78,12,34,32,29,64};`
+
+排序过程:
+
+$i=0\rightarrow 12,\overline{34},78,45,34,32,29,64$
+
+$i=1\rightarrow 12,29,78,45,34,32,\overline{34},64$
+
+$i=2\rightarrow 12,29,32,45,34,78,\overline{34},64$
+
+$i=3\rightarrow 12,29,32,34,45,78,\overline{34},64$
+
+$i=4\rightarrow 12,29,32,34,\overline{34},78,45,64$
+
+$i=5\rightarrow 12,29,32,34,\overline{34},45,78,64$
+
+$i=6\rightarrow 12,29,32,34,\overline{34},45,64,78$
+
+
+程序代码:
+```c
+///
+/// 直接选择排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void StraightSelectSort(T[] array) where T : IComparable
+{
+ for (int i = 0; i < array.Length - 1; i++)
+ {
+ int minIndex = i;
+ T min = array[i];
+
+ for (int j = i + 1; j < array.Length; j++)
+ {
+ if (array[j].CompareTo(min) < 0)
+ {
+ min = array[j];
+ minIndex = j;
+ }
+ }
+ if (minIndex != i)
+ {
+ array[minIndex] = array[i];
+ array[i] = min;
+ }
+ }
+}
+```
+
+直接选择排序是不稳定的。
+
+### 3.2 堆选择排序
+
+直接选择排序并没有把每一趟的比较结果保存下来,在后一趟的比较中,许多比较在前一趟已经做过了,但由于前一趟排序时未保存这些比较结果,所以后一趟排序时又重复执行了这些比较操作,因而执行的比较次数较多。
+
+如果可以做到每次在选择到最小记录的同时,并根据比较结果对其他记录做出相应的调整,那样排序的总体效率就会非常高了。而堆选择排序是一种树形选择排序,是对直接选择排序的有效改进。堆选择排序算法是Floyd和Williams在1964年共同发明的,同时,他们也发明了“堆”这样的数据结构。
+
+堆的概念:具有$n$个元素的序列$K=\lbrace k_1,k_2,⋯,k_n \rbrace$当且仅当满足
+
+
+$$
+\begin{cases}
+k_i\leq k_{2i}\\
+k_i\leq k_{2i+1}
+\end{cases},
+\begin{cases}
+k_i\geq k_{2i}\\
+k_i\geq k_{2i+1}
+\end{cases},
+i=1,2,\cdots,\left[\frac{n}{2}\right]
+$$
+
+时称之为堆。
+
+若关键码的集合$K=\lbrace k_1,k_2,⋯,k_n \rbrace$,把它们按照完全二叉树的顺序存放在一维数组中。
+- 若满足$k_i\leq k_{2i}$且$k_i\leq k_{2i+1}$则称作小根堆。
+- 若满足$k_i\geq k_{2i}$且$k_i \geq k_{2i+1}$则称作大根堆。
+
+小根堆:`int[] Key = new int[]{9,17,65,23,45,78,87,53,31,58,64};`
+
+
+
+
+
+大根堆:`int[] Key = new int[]{94,93,75,91,85,44,51,18,48,58,10,34};`
+
+
+
+思想(以大根堆为例):
+构建大根堆之后,输出堆顶记录,对剩余的$n-1$个记录接着构建大根堆,便可得到$n$个记录的次大值,如此反复执行,就能得到一个有序序列,这个过程称为堆选择排序。
+
+堆选择排序需解决的两个问题:
+
+问题1:如何建堆,对初始序列建堆的过程,就是一个反复进行筛选的过程。
+
+- (1)对一棵具有$n$个结点的完全二叉树来说最后一个结点是第$[\frac{n}{2}]$个结点的子树。
+- (2)筛选从第$[\frac{n}{2}]$个结点为根的子树开始,该子树成为堆。
+- (3)之后向前依次对各结点为根的子树进行筛选,使之成为堆,直到根结点。
+
+即把序号为$[\frac{n}{2}],[\frac{n}{2}]-1,\cdots,1$,的记录作为根的子树都调整为堆。
+
+问题2:输出堆顶元素后,如何调整新堆。
+
+- (1)设有$n$个元素的堆,输出堆顶元素后,剩下$n-1$个元素。将堆底元素送入堆顶(最后一个元素与堆顶进行交换),堆被破坏,其原因仅是根结点不满足堆的性质。
+- (2)将根结点与左,右子树中较大元素进行交换。
+- (3)若与左子树交换:如果左子树堆被破坏,即左子树的根结点不满足堆的性质,则重复第二步。
+- (4)若与右子树交换:如果右子树堆被破坏,即右子树的根结点不满足堆的性质,则重复第二步。
+- (5)继续对不满足堆性质的子树进行上述操作,直到叶子结点,堆被重建成。
+
+即:输出堆顶元素,将最后一个叶子结点放在堆顶,重新构建大根堆。
+
+如:`int[] Key = new int[]{45,34,78,12,34,32,29,64};`
+
+排序过程:
+
+初始时:$Key1 \rightarrow -1,45,\overline{34},78,12,34,32,29,64$
+
+建堆后:$Key1 \rightarrow -1,78,64,45,\overline{34},34,32,29,12$
+
+
+
+
+堆重建后:
+
+$Key1 \rightarrow -1,64,\overline{34},45,12,34,32,29,[78]$
+
+$Key1 \rightarrow -1,45,\overline{34},32,12,34,29,[64,78]$
+
+$Key1 \rightarrow -1,\overline{34},34,32,12,29,[45,64,78]$
+
+$Key1 \rightarrow -1,34,29,32,12,[\overline{34},45,64,78]$
+
+$Key1 \rightarrow -1,32,29,12,[34,\overline{34},45,64,78]$
+
+$Key1 \rightarrow -1,29,12,[32,34,\overline{34},45,64,78]$
+
+$Key1 \rightarrow -1,12,[29,32,34,\overline{34},45,64,78]$
+
+
+
+程序代码:
+```c
+private static void Restore(T[] array, int j, int vCount) where T : IComparable
+{
+ //构建以结点j为根,一共有vCount个结点的大根堆
+ while (j <= vCount / 2)
+ {
+ int m = (2 * j + 1 <= vCount && array[2 * j + 1].CompareTo(array[2 * j]) > 0)
+ ? 2 * j + 1
+ : 2 * j;
+ if (array[m].CompareTo(array[j]) > 0)
+ {
+ T temp = array[m];
+ array[m] = array[j];
+ array[j] = temp;
+ j = m;
+ }
+ else
+ {
+ break;
+ }
+ }
+}
+
+///
+/// 堆选择排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void HeapSelectSort(T[] array) where T : IComparable
+{
+ int vCount = array.Length;
+ T[] tempArray = new T[vCount + 1];
+
+ for (int i = 0; i < vCount; i++)
+ tempArray[i + 1] = array[i];
+
+ //初建大根堆
+ for (int i = vCount / 2; i >= 1; i--)
+ Restore(tempArray, i, vCount);
+
+ //大根堆的重构与排序
+ for (int i = vCount; i > 1; i--)
+ {
+ T temp = tempArray[i];
+ tempArray[i] = tempArray[1];
+ tempArray[1] = temp;
+ Restore(tempArray, 1, i - 1);
+ }
+
+ for (int i = 0; i < vCount; i++)
+ array[i] = tempArray[i + 1];
+}
+```
+
+## 4. 交换排序
+
+### 4.1 冒泡交换排序
+
+思想:通过相邻记录之间的比较和交换,使关键字较小的记录如气泡一般逐渐向上漂移直至水面。
+
+如:`int[] Key = new int[]{45,34,78,12,34,32,29,64};`
+
+$i=0\rightarrow [12],45,\overline{34},78,29,34,32,64$
+
+$i=1\rightarrow [12,29],45,\overline{34},78,32,34,64$
+
+$i=2\rightarrow [12,29,32],45,\overline{34},78,34,64$
+
+$i=3\rightarrow [12,29,32,\overline{34}],45,34,78,64$
+
+$i=4\rightarrow [12,29,32,\overline{34},34],45,64,78$
+
+$i=5\rightarrow [12,29,32,\overline{34},34,45],64,78$
+
+$i=6\rightarrow [12,29,32,\overline{34},34,45,64],78$
+
+
+程序代码:
+```c
+///
+/// 冒泡交换排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void BubbleExchangeSort(T[] array) where T : IComparable
+{
+ for (int i = 0; i < array.Length - 1; i++)
+ {
+ for (int j = array.Length - 1; j > i; j--)
+ {
+ if (array[j].CompareTo(array[j - 1]) < 0)
+ {
+ T temp = array[j - 1];
+ array[j - 1] = array[j];
+ array[j] = temp;
+ }
+ }
+ }
+}
+```
+
+对冒泡排序常见的改进方法是加入一个标志性变量`flag`,用于标志某一趟排序过程是否有数据交换,如果进行某一趟排序时并没有进行数据交换,则说明数据已经按要求排列好,可立即结束排序,避免不必要的比较过程。
+
+
+程序代码:
+```c
+///
+/// 改进的冒泡交换排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void BubbleExchangeSortImproved(T[] array) where T : IComparable
+{
+ for (int i = 0; i < array.Length - 1; i++)
+ {
+ bool flag = false;
+ for (int j = array.Length - 1; j > i; j--)
+ {
+ if (array[j].CompareTo(array[j - 1]) < 0)
+ {
+ T temp = array[j - 1];
+ array[j - 1] = array[j];
+ array[j] = temp;
+ flag = true;
+ }
+ }
+ if (flag == false)
+ break;
+ }
+}
+```
+
+### 4.2 快速交换排序
+
+快速交换排序是由图灵奖获得者Tony Hoare(东尼.霍尔)所发展的一种排序算法,是采用分治策略的一个非常典型的应用。快速交换排序虽然高端,但其思想是来自冒泡交换排序的,冒泡交换排序是通过相邻元素的比较和交换把最小的冒泡到最顶端,而快速交换排序是比较和交换小数和大数,这样一来不仅小数冒泡到上面的同时也把大数沉到下面。
+
+其基本思想如下:
+
+- (1)选择一个基准元素,通常选择第一个元素或者最后一个元素。
+- (2)通过一趟排序将待排序的记录分割成独立的两部分,其中一部分记录的元素值均比基准元素值小,另一部分记录的元素值比基准值大。
+- (3)此时基准元素在其排好序的正确位置。
+- (4)然后分别对这两部分记录用同样的方法继续进行排序,直到整个序列有序。
+
+即:从待排记录中选一记录,将其放入正确的位置,然后以该位置为界,对左右两部分再做快速排序,直到划分的长度为1。
+
+如:`int[] Key = new int[]{45,34,78,12,34,32,29,64};`
+
+
+$init\rightarrow 45,\overline{34},78,12,34,32,29,64$
+
+$step1\rightarrow [32,\overline{34},29,12,34],45,[78,64]$
+
+$step2\rightarrow [[29,12],32,[\overline{34},34]],45,[78,64]$
+
+$step3\rightarrow [[[12],29],32,[\overline{34},34]],45,[78,64]$
+
+$step4\rightarrow [[[12],29],32,[[34],\overline{34}]],45,[78,64]$
+
+$step5\rightarrow [[[12],29],32,[[34],\overline{34}]],45,[[64],78]$
+
+
+程序代码:
+```c
+private static void QuickSort(T[] array, int left, int right) where T : IComparable
+{
+ //快速排序递归函数
+ if (left < right)
+ {
+ T current = array[left];
+ int i = left;
+ int j = right;
+ while (i < j)
+ {
+ while (array[j].CompareTo(current) > 0 && i < j)
+ j--;
+ while (array[i].CompareTo(current) <= 0 && i < j)
+ i++;
+ if (i < j)
+ {
+ T temp = array[i];
+ array[i] = array[j];
+ array[j] = temp;
+ j--;
+ i++;
+ }
+ }
+ array[left] = array[j];
+ array[j] = current;
+ if (left < j - 1) QuickSort(array, left, j - 1);
+ if (right > j + 1) QuickSort(array, j + 1, right);
+ }
+}
+
+///
+/// 快速交换排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void QuickExchangeSort(T[] array) where T : IComparable
+{
+ QuickSort(array, 0, array.Length - 1);
+}
+```
+
+其实上面的代码还可以再优化,上面代码中基准元素已经在`current`中保存了,所以不需要每次交换都设置一个`temp`变量,在交换的时候只需要先后覆盖就可以了。这样既能较少空间的使用还能降低赋值运算的次数。
+
+优化代码如下:
+
+```c
+private static void QuickSortImproved(T[] array, int left, int right) where T : IComparable
+{
+ //快速排序递归函数
+ if (left < right)
+ {
+ T current = array[left];
+ int i = left;
+ int j = right;
+ while (i < j)
+ {
+ while (array[j].CompareTo(current) > 0 && i < j)
+ j--;
+ array[i] = array[j];
+
+ while (array[i].CompareTo(current) <= 0 && i < j)
+ i++;
+ array[j] = array[i];
+ }
+ array[j] = current;
+ if (left < j - 1) QuickSortImproved(array, left, j - 1);
+ if (right > j + 1) QuickSortImproved(array, j + 1, right);
+ }
+}
+
+///
+/// 快速交换排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void QuickExchangeSortImproved(T[] array) where T : IComparable
+{
+ QuickSortImproved(array, 0, array.Length - 1);
+}
+```
+
+## 5. 并归排序
+
+我们首先先看两个有序序列合并的例子,如:
+
+```c
+int[] Key1 = new int[]{1,3,5,7,9};
+int[] Key2 = new int[]{2,4,6,8,10,12,14}
+
+int[] temp = new int[Key1.Length + Key2.Length];
+```
+$temp \rightarrow 0,0,0,0,0,0,0,0,0,0,0,0$
+
+$temp \rightarrow 1,2,3,4,5,6,7,8,9,0,0,0$
+
+$temp \rightarrow 1,2,3,4,5,6,7,8,9,10,12,14$
+
+程序代码:
+
+```c
+///
+/// 合并排序
+///
+/// 需要排序记录的类型
+/// 有序记录集合1
+/// 有序记录集合2
+/// 合并后的有序记录集合
+public static T[] MergeSort(T[] array1,T[] array2) where T : IComparable
+{
+ T[] temp = new T[array1.Length + array2.Length];
+ int i = 0, j = 0, k = 0;
+ while (i < array1.Length && j < array2.Length)
+ {
+ if (array1[i].CompareTo(array2[i]) < 0)
+ {
+ temp[k++] = array1[i++];
+ }
+ else
+ {
+ temp[k++] = array2[j++];
+ }
+ }
+ while (i < array1.Length)
+ {
+ temp[k++] = array1[i++];
+ }
+ while (j < array2.Length)
+ {
+ temp[k++] = array2[j++];
+ }
+ return temp;
+}
+```
+
+我们接着看一个序列的并归排序。
+
+首先递归划分子问题,然后合并结果。把待排序列看成由两个有序的子序列构成,然后合并两个子序列,接着把子序列看成由两个有序序列组成……。倒过来看,其实就是先两两合并,然后四四合并……最终形成有序序列。该算法是采用分治策略的一个非常典型的应用,俗称 **2-路并归**。
+
+如:`int[] Key = new int[]{45,34,78,12,34,32,29,64};`
+
+
+
+程序代码:
+```c
+///
+/// 合并排序的递归合并函数
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+/// 起点位置
+/// 中间位置
+/// 终点位置
+private static void Merge(T[] array, int left, int mid, int right) where T : IComparable
+{
+ T[] temp = new T[right - left + 1];
+ int i = left;
+ int j = mid + 1;
+ int k = 0;
+ while (i <= mid && j <= right)
+ {
+ if (array[i].CompareTo(array[j]) < 0)
+ {
+ temp[k++] = array[i++];
+ }
+ else
+ {
+ temp[k++] = array[j++];
+ }
+ }
+ while (i <= mid)
+ {
+ temp[k++] = array[i++];
+ }
+ while (j <= right)
+ {
+ temp[k++] = array[j++];
+ }
+ for (int n = 0; n < temp.Length; n++)
+ {
+ array[left + n] = temp[n];
+ }
+}
+
+///
+/// 合并排序的递归分治函数
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+/// 起点位置
+/// 终点位置
+private static void MergeSort(T[] array, int left, int right) where T : IComparable
+{
+ if (left >= right)
+ return;
+
+ int mid = (left + right) / 2;
+ MergeSort(array, left, mid); //递归排序左边
+ MergeSort(array, mid + 1, right); //递归排序右边
+ Merge(array, left, mid, right); //合并
+}
+
+
+///
+/// 合并排序
+///
+/// 需要排序记录的类型
+/// 需要排序的记录集合
+public static void MergeSort(T[] array) where T : IComparable
+{
+ MergeSort(array, 0, array.Length - 1);
+}
+```
+
+
diff --git a/DataStructureAndAlgorithm/11 Leetcode同步练习(四).md b/DataStructureAndAlgorithm/11 Leetcode同步练习(四).md
deleted file mode 100644
index f839e68..0000000
--- a/DataStructureAndAlgorithm/11 Leetcode同步练习(四).md
+++ /dev/null
@@ -1,1171 +0,0 @@
-# Leetcodeͬϰģ
-
-## Ŀ01Сջ
-
-> - ţ155
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/min-stack/
-
-һ֧ pushpoptop ڳʱڼСԪصջ
-
-- push(x) -- Ԫ x ջС
-- pop() -- ɾջԪء
-- top() -- ȡջԪء
-- getMin() -- ջеСԪء
-
-ʾ:
-
-```c
-MinStack minStack = new MinStack();
-minStack.push(-2);
-minStack.push(0);
-minStack.push(-3);
-minStack.getMin(); --> -3.
-minStack.pop();
-minStack.top(); --> 0.
-minStack.getMin(); --> -2.
-```
-
-**˼·**øջķʽ
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 192 ms, C# ύл 96.43% û
-- ڴ: 33.5 MB, C# ύл 13.63% û
-
-```c
-public class MinStack
-{
- /** initialize your data structure here. */
- private readonly Stack _stack;
- private readonly Stack _stackMin;
-
- public MinStack()
- {
- _stack = new Stack();
- _stackMin = new Stack();
- }
-
- public void Push(int x)
- {
- _stack.Push(x);
- if (_stackMin.Count == 0 || _stackMin.Peek() >= x)
- {
- _stackMin.Push(x);
- }
- }
-
- public void Pop()
- {
- int x = _stack.Pop();
- if (_stackMin.Peek() == x)
- {
- _stackMin.Pop();
- }
- }
-
- public int Top()
- {
- return _stack.Peek();
- }
-
- public int GetMin()
- {
- return _stackMin.Peek();
- }
-}
-
-/**
- * Your MinStack object will be instantiated and called as such:
- * MinStack obj = new MinStack();
- * obj.Push(x);
- * obj.Pop();
- * int param_3 = obj.Top();
- * int param_4 = obj.GetMin();
- */
-```
-
-
-
-
----
-## Ŀ02Ч
-
-> - ţ20
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/valid-parentheses/
-
-һֻ '('')''{''}''['']' ַжַǷЧ
-
-Чַ㣺
-
-- űͬ͵űպϡ
-- űȷ˳պϡ
-
-עַɱΪЧַ
-
-ʾ 1:
-```c
-: "()"
-: true
-```
-
-ʾ 2:
-```c
-: "()[]{}"
-: true
-```
-
-ʾ 3:
-```c
-: "(]"
-: false
-```
-
-ʾ 4:
-```c
-: "([)]"
-: false
-```
-
-ʾ 5:
-```c
-: "{[]}"
-: true
-```
-
-ʾ 6:
-```c
-: ""
-: true
-```
-
-
-
-ʾ 7:
-```c
-: "(("
-: false
-```
-
-**˼·**ջ
-
-жϸַȵżԣfalseջȽص㣬{[(ջ}])ջԪؽбȽϣǶӦջfalse
-
-**ο**
-
-- ִнͨ
-- ִʱ88 ms, C# ύл 70.31% û
-- ڴģ22 MB, C# ύл 17.91% û
-
-
-```c
-public class Solution {
- public bool IsValid(string s)
- {
- if (string.IsNullOrEmpty(s))
- return true;
-
- int count = s.Length;
- if(count%2 == 1)
- return false;
-
- Stack stack = new Stack();
- for (int i = 0; i < count; i++)
- {
- char c = s[i];
- if (stack.Count == 0)
- {
- stack.Push(c);
- }
- else if(c == '[' || c == '{' || c == '(')
- {
- stack.Push(c);
- }
- else if (stack.Peek() == GetPair(c))
- {
- stack.Pop();
- }
- else
- {
- return false;
- }
- }
- return stack.Count == 0;
- }
-
- public static char GetPair(char c)
- {
- if (c == ')')
- return '(';
- if (c == '}')
- return '{';
- if (c == ']')
- return '[';
- return '\0';
- }
-}
-```
-
----
-## Ŀ03öʵջ
-
-> - ţ225
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/implement-stack-using-queues/
-
-ʹöʵջв
-
-- `push(x)` -- Ԫ x ջ
-- `pop()` -- ƳջԪ
-- `top()` -- ȡջԪء
-- `empty()` -- ջǷΪ
-
-**ע:**
-
-- ֻʹöеĻ-- Ҳ push to back, peek/pop from front, size, is empty ЩǺϷġ
-- ʹõҲֶ֧Сʹ `list` `deque`˫˶Уģһ, ֻҪDZĶвɡ
-- ԼвЧģ, һյջ `pop` `top`
-
-
-**˼·**νʵջӻʱѭǰn-1ڵ㣬Ӷ׳Ӻټڶβʵֶӷ
-
-**ο룺**
-
-- ִнͨ
-- ִʱ124 ms, C# ύл 56.21% û
-- ڴģ23.4 MB, C# ύл 63.73% û
-
-```c
-public class MyStack
-{
- Queue queue = new Queue();
-
- /** Initialize your data structure here. */
- public MyStack()
- {
- }
-
- /** Push element x onto stack. */
- public void Push(int x)
- {
- queue.Enqueue(x);
- for (int i = 0; i < queue.Count - 1; i++)
- {
- queue.Enqueue(queue.Dequeue());
- }
- }
-
- /** Removes the element on top of the stack and returns that element. */
- public int Pop()
- {
- return queue.Count > 0 ? queue.Dequeue() : -1;
- }
-
- /** Get the top element. */
- public int Top()
- {
- return queue.Count > 0 ? queue.Peek() : -1;
- }
-
- /** Returns whether the stack is empty. */
- public bool Empty()
- {
- return queue.Count == 0;
- }
-}
-
-/**
- * Your MyStack object will be instantiated and called as such:
- * MyStack obj = new MyStack();
- * obj.Push(x);
- * int param_2 = obj.Pop();
- * int param_3 = obj.Top();
- * bool param_4 = obj.Empty();
- */
-```
-
-
----
-## Ŀ04ת
-
-> - ţ7
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/reverse-integer/
-
-
-һ 32 λзҪÿλϵֽзת
-
-ʾ 1:
-```python
-: 123
-: 321
-```
-
-ʾ 2:
-```python
-: -123
-: -321
-```
-
-ʾ 3:
-```python
-: 120
-: 21
-```
-ʾ 4:
-```python
-: 21474836472^31 ? 1 = int.MaxValue
-: 0
-```
-ʾ 5:
-```python
-: -2147483648?2^31 = int.MinValue
-: 0
-```
-
-
-ע
-
-ǵĻֻܴ洢 32 λзֵΧΪ`[?2^31, 2^31 ? 1]`裬תôͷ 0
-
-
-**˼·**ͨеķʽѸתΪͨСͳһ
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 56 ms, C# ύл 93.28% û
-- ڴ: 13.9 MB, C# ύл 13.98% û
-
-```c
-public class Solution {
- public int Reverse(int x) {
- if (x == int.MinValue)
- return 0;
-
- long result = 0;
- int negative = x < 0 ? -1 : 1;
- x = negative * x;
-
- Queue q = new Queue();
- while (x != 0)
- {
- q.Enqueue(x % 10);
- x = x/10;
- }
-
- while (q.Count != 0)
- {
- result += q.Dequeue()*(long) Math.Pow(10, q.Count);
- if (negative == 1 && result > int.MaxValue)
- {
- result = 0;
- break;
- }
- if (negative == -1 && result*-1 < int.MinValue)
- {
- result = 0;
- break;
- }
- }
- return (int)result*negative;
- }
-}
-```
-
----
-## Ŀ05沨ʽֵ
-
-> - ţ150
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/
-
-沨ʾʽֵ
-
-Ч +, -, *, / ÿҲһ沨ʽ
-
-˵
-
-- ֻ֡
-- 沨ʽЧġ仰˵ʽܻóЧֵҲڳΪ 0
-
-ʾ 1
-
-```c
-: ["2", "1", "+", "3", "*"]
-: 9
-: ((2 + 1) * 3) = 9
-```
-
-ʾ 2
-
-```c
-: ["4", "13", "5", "/", "+"]
-: 6
-: (4 + (13 / 5)) = 6
-```
-
-ʾ 3
-
-```c
-: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
-: 22
-:
- ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
-= ((10 * (6 / (12 * -11))) + 17) + 5
-= ((10 * (6 / -132)) + 17) + 5
-= ((10 * 0) + 17) + 5
-= (0 + 17) + 5
-= 17 + 5
-= 22
-```
-
-
-
-**˼·**ջȳԽ㷨ʵ֡
-
-**ο**
-
-- ִнͨ
-- ִʱ100 ms, C# ύл 100.00% û
-- ڴģ25 MB, C# ύл 69.81% û
-
-```c
-public class Solution {
- public int EvalRPN(string[] tokens)
- {
- Stack stack = new Stack();
- for (int i = 0; i < tokens.Length; i++)
- {
- string str = tokens[i];
- if (str == "+" || str == "-" || str == "*" || str == "/")
- {
- int b = stack.Pop();
- int a = stack.Pop();
- int c = Compute(a, b, str);
- stack.Push(c);
- }
- else
- {
- stack.Push(int.Parse(str));
- }
- }
- return stack.Pop();
- }
-
- public static int Compute(int a, int b, string oper)
- {
- int result = 0;
- switch (oper)
- {
- case "+":
- result = a + b;
- break;
- case "-":
- result = a - b;
- break;
- case "*":
- result = a * b;
- break;
- case "/":
- result = a / b;
- break;
- }
- return result;
- }
-}
-```
-
-
----
-## Ŀ06ȫ
-
-> - ţ46
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/permutations/
-
-һûظֵУпܵȫС
-
-ʾ:
-```c
-: [1,2,3]
-:
-[
- [1,2,3],
- [1,3,2],
- [2,1,3],
- [2,3,1],
- [3,1,2],
- [3,2,1]
-]
-```
-
-
-
-˼·ݷback tracking һѡֳΪ̽ѡǰԴﵽĿꡣ̽ijһʱԭѡŻﲻĿ꣬˻һѡ߲ͨ˻ߵļΪݷij״̬ĵΪݵ㡱
-
-> ݷΪͨѡͬIJ·ѰĿĵأһ·һ·ڵȥҵĿĵءߴ·ҵ·ڵһ·ֱҵĿĵء
-
-ϰĻݹʾ
-
-
-
-
-**ο룺**
-
-- ״̬ͨ
-- ִʱ: 364 ms, C# ύл 80.00% û
-- ڴ: 30.6 MB, C# ύл 7.14% û
-
-```c
-public class Solution
-{
- private IList> _result;
- private bool[] _used;
-
- public IList> Permute(int[] nums)
- {
- _result = new List>();
- if (nums == null || nums.Length == 0)
- return _result;
- _used = new bool[nums.Length];
-
- FindPath(nums, 0, new List());
- return _result;
- }
-
- public void FindPath(int[] nums, int count, List path)
- {
- if (count == nums.Length)
- {
- //ݹֹ
- List item = new List();
- item.AddRange(path);
- //뿽
- _result.Add(item);
- return;
- }
- for (int i = 0; i < nums.Length; i++)
- {
- if (_used[i] == false)
- {
- path.Add(nums[i]);
- _used[i] = true;
- FindPath(nums, count + 1, path);
- path.RemoveAt(path.Count - 1);
- _used[i] = false;
- }
- }
- }
-}
-```
-
-
-
-
----
-## Ŀ07ַת (atoi)
-
-> - ţ8
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/string-to-integer-atoi/
-
-ʵһ `atoi` ʹַܽת
-
-ȣúҪõĿͷոֱַѰҵһǿոַΪֹ
-
-ѰҵĵһǿַΪ߸ʱ÷֮澡ܶΪţһǿֱַ֣ӽַ֮γ
-
-ַЧ֮ҲܻڶַЩַԱԣǶںӦӰ졣
-
-ע⣺ַеĵһǿոַһЧַַΪջַհַʱĺҪת
-
-κ£ܽЧתʱ뷵 0
-
-˵
-
-ǵĻֻܴ洢 32 λСзôֵΧΪ `[?2^31, 2^31? 1]`ֵΧ뷵 `INT_MAX (2^31? 1)` `INT_MIN (?2^31)`
-
-ʾ 1:
-```c
-: "42"
-: 42
-```
-
-ʾ 2:
-```c
-: " -42"
-: -42
-: һǿհַΪ '-', һš
-Ǿֵܽõ -42
-```
-ʾ 3:
-```c
-: "4193 with words"
-: 4193
-: תֹ '3' ΪһַΪ֡
-```
-
-ʾ 4:
-```c
-: "words and 987"
-: 0
-: һǿַ 'w', ֻš
-ִЧת
-```
-
-ʾ 5:
-```c
-: "-91283472332"
-: -2147483648
-: "-91283472332" 32 λзΧ
-˷ INT_MIN (?231)
-```
-
-
-ʾ 6:
-```c
-: " 0000000000012345678"
-: 12345678
-```
-
-ʾ 7:
-```c
-: "20000000000000000000"
-: 2147483647
-```
-
-**˼·**ͨеķʽ
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 104 ms, C# ύл 98.32% û
-- ڴ: 24.3 MB, C# ύл 24.45% û
-
-```c
-public class Solution {
- public int MyAtoi(string str) {
- str = str.Trim();
- if (string.IsNullOrEmpty(str))
- return 0;
-
- if (str[0] != '-' && str[0] != '+')
- {
- if (str[0] < '0' || str[0] > '9')
- return 0;
- }
- int negative = 1;
- long result = 0;
- Queue q = new Queue();
- for (int i = 0; i < str.Length; i++)
- {
- if (str[i] == '-' && i == 0)
- {
- negative = -1;
- continue;
- }
- if (str[i] == '+' && i == 0)
- {
- continue;
- }
- if (str[i] < '0' || str[i] > '9')
- {
- break;
- }
- q.Enqueue(str[i] - '0');
- }
-
- while (q.Count != 0)
- {
- int i = q.Dequeue();
-
- //ȥǰ˵
- if (i == 0 && result == 0)
- continue;
-
- // سλ
- if (negative == 1 && q.Count > 10)
- {
- return int.MaxValue;
- }
- if (negative == -1 && q.Count > 10)
- {
- return int.MinValue;
- }
-
- result += i * (long)Math.Pow(10, q.Count);
- if (negative == 1 && result > int.MaxValue)
- {
- return int.MaxValue;
- }
- if (negative == -1 && result * -1 < int.MinValue)
- {
- return int.MinValue;
- }
- }
- return (int)result * negative;
- }
-}
-```
-
----
-## Ŀ08ѭ˫˶
-
-> - ţ641
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/design-circular-deque/
-
-ʵ˫˶С
-
-ʵҪ֧²
-
-- `MyCircularDeque(k)`캯,˫˶еĴСΪk
-- `insertFront()`һԪӵ˫˶ͷ ɹ true
-- `insertLast()`һԪӵ˫˶βɹ true
-- `deleteFront()`˫˶ͷɾһԪء ɹ true
-- `deleteLast()`˫˶βɾһԪءɹ true
-- `getFront()`˫˶ͷһԪء˫˶Ϊգ -1
-- `getRear()`˫˶еһԪء˫˶Ϊգ -1
-- `isEmpty()`˫˶ǷΪա
-- `isFull()`˫˶Ƿˡ
-
-ʾ
-
-```c
-MyCircularDeque circularDeque = new MycircularDeque(3); // СΪ3
-circularDeque.insertLast(1); // true
-circularDeque.insertLast(2); // true
-circularDeque.insertFront(3); // true
-circularDeque.insertFront(4); // Ѿˣ false
-circularDeque.getRear(); // 2
-circularDeque.isFull(); // true
-circularDeque.deleteLast(); // true
-circularDeque.insertFront(4); // true
-circularDeque.getFront(); // 4
-```
-
-ʾ
-
-- ֵķΧΪ [1, 1000]
-- ķΧΪ [1, 1000]
-- 벻Ҫʹõ˫˶п⡣
-
-
-**ο**
-
-- ִнͨ
-- ִʱ160 ms, C# ύл 90.48% û
-- ڴģ34.7 MB, C# ύл 7.14% û
-
-
-```c
-public class MyCircularDeque
-{
- private int _pFront;
- private int _pRear;
- private readonly int[] _dataset;
- private int _length;
- private int _maxSize;
-
- /** Initialize your data structure here. Set the size of the deque to be k. */
- public MyCircularDeque(int k)
- {
- _dataset = new int[k];
- _length = 0;
- _maxSize = k;
- _pFront = 0;
- _pRear = 0;
- }
-
- /** Adds an item at the front of Deque. Return true if the operation is successful. */
- public bool InsertFront(int value)
- {
- if (_length == _maxSize)
- return false;
-
- _pFront = (_pFront - 1 + _maxSize)%_maxSize;
- _dataset[_pFront] = value;
- _length++;
- return true;
- }
-
- /** Adds an item at the rear of Deque. Return true if the operation is successful. */
- public bool InsertLast(int value)
- {
- if (_length == _maxSize)
- return false;
-
- _dataset[_pRear] = value;
- _pRear = (_pRear + 1)%_maxSize;
- _length++;
- return true;
- }
-
- /** Deletes an item from the front of Deque. Return true if the operation is successful. */
- public bool DeleteFront()
- {
- if (_length == 0)
- return false;
- _pFront = (_pFront + 1)%_maxSize;
- _length--;
- return true;
- }
-
- /** Deletes an item from the rear of Deque. Return true if the operation is successful. */
- public bool DeleteLast()
- {
- if (_length == 0)
- return false;
- _pRear = (_pRear - 1 + _maxSize)%_maxSize;
- _length--;
- return true;
- }
-
- /** Get the front item from the deque. */
- public int GetFront()
- {
- if (_length == 0)
- return -1;
-
- return _dataset[_pFront];
- }
-
- /** Get the last item from the deque. */
- public int GetRear()
- {
- if (_length == 0)
- return -1;
- int index = (_pRear - 1 + _maxSize)%_maxSize;
- return _dataset[index];
- }
-
- /** Checks whether the circular deque is empty or not. */
- public bool IsEmpty()
- {
- return _length == 0;
- }
-
- /** Checks whether the circular deque is full or not. */
- public bool IsFull()
- {
- return _length == _maxSize;
- }
-}
-
-/**
- * Your MyCircularDeque object will be instantiated and called as such:
- * MyCircularDeque obj = new MyCircularDeque(k);
- * bool param_1 = obj.InsertFront(value);
- * bool param_2 = obj.InsertLast(value);
- * bool param_3 = obj.DeleteFront();
- * bool param_4 = obj.DeleteLast();
- * int param_5 = obj.GetFront();
- * int param_6 = obj.GetRear();
- * bool param_7 = obj.IsEmpty();
- * bool param_8 = obj.IsFull();
- */
-```
-
-
-
-
-
----
-## Ŀ09Ч
-
-> - ţ32
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/longest-valid-parentheses/
-
-һֻ '(' ')' ַҳİЧŵӴijȡ
-
-ʾ 1:
-
-```c
-: "(()"
-: 2
-: ЧӴΪ "()"
-```
-
-ʾ 2:
-```c
-: ")()())"
-: 4
-: ЧӴΪ "()()"
-```
-
-ʾ 3:
-```c
-: ""
-: 0
-:
-```
-ʾ 4:
-```c
-: "()(())"
-: 6
-: ЧӴΪ "()(())"
-```
-
-**˼·**ջ
-
-ǿջڱַĹȥжϵĿǰΪֹɨַЧԣͬʱЧַijȡȽ ?1 ջ
-
-- ÿ(ǽ±ջС
-- ÿ)ǵջԪأжЧԣЧȡ
-
-**ο**
-
-- ״̬ͨ
-- ִʱ92 ms, C# ύл 53.78% û
-- ڴģ23.5 MB, C# ύл 7.14% û
-
-```c
-public class Solution {
- public int LongestValidParentheses(string s) {
- Stack stack = new Stack();
- stack.Push(-1);
- int result = 0;
- for (int i = 0; i < s.Length; i++)
- {
- if (s[i] == '(')
- {
- stack.Push(i);
- }
- else
- {
- stack.Pop();
- if (stack.Count == 0)
- {
- stack.Push(i);
- }
- else
- {
- result = Math.Max(result, i - stack.First());
- }
- }
- }
- return result;
- }
-}
-```
-
----
-## Ŀ10ֵ
-
-> - ţ239
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/sliding-window-maximum/
-
-һ numsһСΪ k ĻڴƶҲࡣֻԿڻڵ k ֡ÿֻƶһλ
-
-ػеֵ
-
-ʾ:
-
-```c
-: nums = [1,3,-1,-3,5,3,6,7], k = 3
-: [3,3,5,5,6,7]
-:
-
- ڵλ ֵ
---------------- -----
-[1 3 -1] -3 5 3 6 7 3
- 1 [3 -1 -3] 5 3 6 7 3
- 1 3 [-1 -3 5] 3 6 7 5
- 1 3 -1 [-3 5 3] 6 7 5
- 1 3 -1 -3 [5 3 6] 7 6
- 1 3 -1 -3 5 [3 6 7] 7
-```
-
-ʾ
-
-Լ k Чģ鲻Ϊյ£1 k ĴС
-
-
-
-
-
-ʱ临Ӷڽ
-
-**ο룺**
-
-ʵһѰÿڵֵ
-
-
-- ״̬ͨ
-- ִʱ: 472 ms, C# ύл 53.33% û
-- ڴ: 34.3 MB, C# ύл 50.00% û
-
-```c
-public class Solution {
- public int[] MaxSlidingWindow(int[] nums, int k) {
- int len = nums.Length;
- if (len == 0)
- return nums;
-
- int[] result = new int[len - k + 1];
- for (int i = 0; i < result.Length; i++)
- {
- result[i] = GetMax(nums, i, i + k);
- }
- return result;
- }
-
- public int GetMax(int[] arr,int start,int end)
- {
- int max = int.MinValue;
- for (int i = start; i < end; i++)
- {
- if (arr[i] > max)
- max = arr[i];
- }
- return max;
- }
-}
-```
-
-ʵֶʱЧʾҪʹýṹˡ
-
-- ״̬ͨ
-- ִʱ: 364 ms, C# ύл 75.33% û
-- ڴ: 40.5 MB, C# ύл 100.00% û
-
-
-**˼·**ѭ˫˶¼ǰڵϢдֵλü¼ڶԪС˫˶Ҫ֤λõֵɴС
-- ҪɾԪء
-- ڶβԪأҪɾβԪأѸԪصλò뵽β
-
-
-```c
-public class MyCircularDeque
-{
- private int _pFront;
- private int _pRear;
- private readonly int[] _dataset;
- private int _length;
- private int _maxSize;
-
- /** Initialize your data structure here. Set the size of the deque to be k. */
- public MyCircularDeque(int k)
- {
- _dataset = new int[k];
- _length = 0;
- _maxSize = k;
- _pFront = 0;
- _pRear = 0;
- }
-
- /** Adds an item at the front of Deque. Return true if the operation is successful. */
- public bool InsertFront(int value)
- {
- if (_length == _maxSize)
- return false;
-
- _pFront = (_pFront - 1 + _maxSize) % _maxSize;
- _dataset[_pFront] = value;
- _length++;
- return true;
- }
-
- /** Adds an item at the rear of Deque. Return true if the operation is successful. */
- public bool InsertLast(int value)
- {
- if (_length == _maxSize)
- return false;
-
- _dataset[_pRear] = value;
- _pRear = (_pRear + 1) % _maxSize;
- _length++;
- return true;
- }
-
- /** Deletes an item from the front of Deque. Return true if the operation is successful. */
- public bool DeleteFront()
- {
- if (_length == 0)
- return false;
- _pFront = (_pFront + 1) % _maxSize;
- _length--;
- return true;
- }
-
- /** Deletes an item from the rear of Deque. Return true if the operation is successful. */
- public bool DeleteLast()
- {
- if (_length == 0)
- return false;
- _pRear = (_pRear - 1 + _maxSize) % _maxSize;
- _length--;
- return true;
- }
-
- /** Get the front item from the deque. */
- public int GetFront()
- {
- if (_length == 0)
- return -1;
-
- return _dataset[_pFront];
- }
-
- /** Get the last item from the deque. */
- public int GetRear()
- {
- if (_length == 0)
- return -1;
- int index = (_pRear - 1 + _maxSize) % _maxSize;
- return _dataset[index];
-
- }
-
- /** Checks whether the circular deque is empty or not. */
- public bool IsEmpty()
- {
- return _length == 0;
- }
-
- /** Checks whether the circular deque is full or not. */
- public bool IsFull()
- {
- return _length == _maxSize;
- }
-}
-
-public class Solution {
- public int[] MaxSlidingWindow(int[] nums, int k) {
- int len = nums.Length;
- if (len == 0)
- return nums;
- int[] result = new int[len - k + 1];
- MyCircularDeque deque = new MyCircularDeque(k);
-
- for (int i = 0; i < len; i++)
- {
- // жϵǰжֵǷЧ
- if (deque.IsEmpty() == false && deque.GetFront() <= i - k)
- {
- deque.DeleteFront();
- }
-
- // ֤ӴС ǰСҪεֱҪ
- while (deque.IsEmpty() == false && nums[deque.GetRear()] <= nums[i])
- {
- deque.DeleteLast();
- }
- //ӵǰֵӦ±
- deque.InsertLast(i);
-
- // ڳΪkʱ 浱ǰֵ
- if (i + 1 >= k)
- {
- result[i + 1 - k] = nums[deque.GetFront()];
- }
- }
- return result;
- }
-}
-```
\ No newline at end of file
diff --git a/DataStructureAndAlgorithm/14 Leetcode同步练习(五).md b/DataStructureAndAlgorithm/14 Leetcode同步练习(五).md
deleted file mode 100644
index 3c02b54..0000000
--- a/DataStructureAndAlgorithm/14 Leetcode同步练习(五).md
+++ /dev/null
@@ -1,1114 +0,0 @@
-# Leetcodeͬϰ壩
-## Ŀ¼
-- Ŀ01ջʵֶ
-- Ŀ02ľ
-- Ŀ03ת
-- Ŀ04ǰ
-- Ŀ05תַ
-- Ŀ06ظַӴ
-- Ŀ07Ӵ
-- Ŀ08ַ
-- Ŀ09ʽƥ
-- Ŀ10ͨƥ
-
-
----
-## Ŀ01ջʵֶ
-
-> - ţ232
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/implement-queue-using-stacks/
-
-ʹջʵֶев
-
-- `push(x)` -- һԪطеβ
-- `pop()` -- ӶײƳԪء
-- `peek()` -- ضײԪء
-- `empty()` -- ضǷΪա
-
-
-ʾ:
-
-```c
-MyQueue queue = new MyQueue();
-
-queue.push(1);
-queue.push(2);
-queue.peek(); // 1
-queue.pop(); // 1
-queue.empty(); // false
-```
-
-˵:
-
-- ֻʹñջ -- Ҳֻpush to toppeek/pop from topsize is empty ǺϷġ
-- ʹõҲ֧ջʹ`list``deque`˫˶УģһջֻҪDZջɡ
-- вЧģ磬һյĶв`pop``peek`
-
-**ο룺**
-
-- ִнͨ
-- ִʱ112 ms, C# ύл 95.10% û
-- ڴģ24.3 MB, C# ύл 5.33% û
-
-```c
-public class MyQueue
-{
- private Stack _stack = new Stack();
-
- /** Initialize your data structure here. */
- public MyQueue()
- {
- ;
- }
-
- /** Push element x to the back of queue. */
- public void Push(int x)
- {
- if (_stack.Count == 0)
- {
- _stack.Push(x);
- return;
- }
-
- Stack temp = new Stack();
- while (_stack.Count != 0)
- {
- temp.Push(_stack.Pop());
- }
- _stack.Push(x);
- while (temp.Count != 0)
- {
- _stack.Push(temp.Pop());
- }
- }
-
- /** Removes the element from in front of queue and returns that element. */
- public int Pop()
- {
- return _stack.Count > 0 ? _stack.Pop() : -1;
- }
-
- /** Get the front element. */
- public int Peek()
- {
- return _stack.Count > 0 ? _stack.Peek() : -1;
- }
-
- /** Returns whether the queue is empty. */
- public bool Empty()
- {
- return _stack.Count == 0;
- }
-}
-
-/**
- * Your MyQueue object will be instantiated and called as such:
- * MyQueue obj = new MyQueue();
- * obj.Push(x);
- * int param_2 = obj.Pop();
- * int param_3 = obj.Peek();
- * bool param_4 = obj.Empty();
- */
-```
-
----
-## Ŀ02ľ
-
-> - ţ766
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/toeplitz-matrix/
-
-
-ÿһϵµĶԽϵԪضͬô ľ
-
-һ`M x N`ľҽľʱ`True`
-
-**ʾ 1:**
-
-```c
-:
-matrix = [
- [1,2,3,4],
- [5,1,2,3],
- [9,5,1,2]
-]
-: True
-:
-, ԽΪ:
-"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]"
-ԽϵԪؾͬ, ˴True
-```
-
-**ʾ 2:**
-
-```c
-:
-matrix = [
- [1,2],
- [2,2]
-]
-: False
-:
-Խ"[1, 2]"ϵԪزͬ
-```
-
-**˵:**
-
-1. `matrix`һĶά顣
-2. `matrix` [1, 20]Χڡ
-3. `matrix[i][j]` [0, 99]Χڡ
-
-
-**:**
-
-1. 洢ڴϣҴڴģһֻܽһоصڴУô죿
-2. ֻ̫һνмصڴУô죿
-
-**˼·**жԽϵԪض$a_{11} = a_{00}, a_{22} = a_{11}, a_{kk} = a_{k-1k-1}$ڶԽϵԪ˵ǰԪزǵһֵԪأôǰԪһڵǰԪصϽǡƳλ$(r, c)$ϵԪأֻҪ`r == 0 OR c == 0 OR matrix[r-1][c-1] == matrix[r][c]`Ϳˡ
-
-**ο**
-
-- ִнͨ
-- ִʱ128 ms, C# ύл 47.50% û
-- ڴģ27.5 MB, C# ύл 16.13% û
-
-```c
-public class Solution
-{
- public bool IsToeplitzMatrix(int[][] matrix)
- {
- for (int i = 1; i < matrix.Length; i++)
- {
- int[] row = matrix[i];
- for (int j = 1; j < row.Length; j++)
- {
- if (matrix[i][j] != matrix[i - 1][j - 1])
- return false;
- }
- }
- return true;
- }
-}
-```
-
-
----
-## Ŀ03ת
-
-> - ţ13
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/roman-to-integer/
-
-ְַ: `I V X LCD``M`
-
-```
-ַ ֵ
-I 1
-V 5
-X 10
-L 50
-C 100
-D 500
-M 1000
-```
-
-磬 2 д`II`Ϊе 112 д`XII`Ϊ`X + II` 27 д`XXVII`, Ϊ`XX + V + II`
-
-
-ͨ£СڴֵұߡҲ 4 д`IIII``IV` 1 5 ߣʾڴ 5 С 1 õֵ 4 ͬأ 9 ʾΪ`IX`Ĺֻ
-
-```
-I Է V (5) X (10) ߣʾ 4 9
-X Է L (50) C (100) ߣʾ 40 90
-C Է D (500) M (1000) ߣʾ 400 900
-```
-
-һ֣תȷ 1 3999 ķΧڡ
-
-**ʾ 1:**
-
-```c
-:"III"
-: 3
-```
-
-**ʾ 2:**
-
-```c
-: "IV"
-: 4
-```
-
-**ʾ 3:**
-```c
-: "IX"
-: 9
-```
-
-**ʾ 4:**
-```c
-: "LVIII"
-: 58
-: L = 50, V= 5, III = 3.
-```
-
-**ʾ 5:**
-```c
-: "MCMXCIV"
-: 1994
-: M = 1000, CM = 900, XC = 90, IV = 4.
-```
-
-**˼·**ֱӷݡСڴֵұߡԼĹֱȥд롣
-
-**ο**
-
-- ִнͨ
-- ִʱ96 ms, C# ύл 95.88% û
-- ڴģ25.7 MB, C# ύл 5.27% û
-
-```c
-public class Solution
-{
- public int RomanToInt(string s)
- {
- int result = 0;
- int count = s.Length;
- int i = 0;
- while (i < count)
- {
- char c = s[i];
- int move = 0;
- switch (c)
- {
- case 'I':
- result += PreI(i, s, ref move);
- break;
- case 'V':
- result += 5;
- move = 1;
- break;
- case 'X':
- result += PreX(i, s, ref move);
- break;
- case 'L':
- result += 50;
- move = 1;
- break;
- case 'C':
- result += PreC(i, s, ref move);
- break;
- case 'D':
- result += 500;
- move = 1;
- break;
- case 'M':
- result += 1000;
- move = 1;
- break;
- }
- i += move;
- }
- return result;
- }
- private int PreI(int index, string s, ref int move)
- {
- //I 1
- //IV 4
- //IX 9
- //II 2
- int result = 0;
- int count = s.Length;
- if (index + 1 < count)
- {
- char c = s[index + 1];
- switch (c)
- {
- case 'V':
- result = 4;
- move = 2;
- break;
- case 'X':
- result = 9;
- move = 2;
- break;
- case 'I':
- result = 2;
- move = 2;
- break;
- }
- }
- else
- {
- result = 1;
- move = 1;
- }
- return result;
- }
-
- private int PreX(int index, string s, ref int move)
- {
- //X 10
- //XL 40
- //XC 90
- int result = 0;
- int count = s.Length;
- if (index + 1 < count)
- {
- char c = s[index + 1];
- switch (c)
- {
- case 'L':
- result = 40;
- move = 2;
- break;
- case 'C':
- result = 90;
- move = 2;
- break;
- default:
- result = 10;
- move = 1;
- break;
- }
- }
- else
- {
- result = 10;
- move = 1;
- }
- return result;
- }
-
- private int PreC(int index, string s, ref int move)
- {
- //C 100
- //CD 400
- //CM 900
- int result = 0;
- int count = s.Length;
- if (index + 1 < count)
- {
- char c = s[index + 1];
- switch (c)
- {
- case 'D':
- result = 400;
- move = 2;
- break;
- case 'M':
- result = 900;
- move = 2;
- break;
- default:
- result = 100;
- move = 1;
- break;
- }
- }
- else
- {
- result = 100;
- move = 1;
- }
- return result;
- }
-}
-```
-
----
-## Ŀ04ǰ
-
-> - ţ14
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/longest-common-prefix/
-
-дһַеǰ
-
-ڹǰؿַ ""
-
-ʾ 1:
-```c
-: ["flower","flow","flight"]
-: "fl"
-```
-
-ʾ 2:
-```c
-: ["dog","racecar","car"]
-: ""
-: 벻ڹǰ
-```
-
-˵:
-
-ֻСдĸ a-z
-
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 144 ms, C# ύл 94.92% û
-- ڴ: 23.4 MB, C# ύл 11.69% û
-
-
-```c
-public class Solution {
- public string LongestCommonPrefix(string[] strs)
- {
- if (strs.Length == 0)
- return string.Empty;
-
- string result = strs[0];
- for (int i = 1; i < strs.Length; i++)
- {
- result = Prefix(result, strs[i]);
- if (string.IsNullOrEmpty(result))
- break;
- }
- return result;
- }
-
- public string Prefix(string str1, string str2)
- {
- int len1 = str1.Length;
- int len2 = str2.Length;
- int len = Math.Min(len1, len2);
- int i = 0;
- for (; i < len; i++)
- {
- if (str1[i] != str2[i])
- break;
- }
- return i == 0 ? string.Empty : str1.Substring(0, i);
- }
-}
-```
-
----
-## Ŀ05תַ
-
-> - ţ344
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/reverse-string/
-
-
-
-дһǽַתַַ char[] ʽ
-
-ҪĿռ䣬ԭ ʹ O(1) Ķռһ⡣
-
-Լеַ ASCII еĿɴӡַ
-
-
-ʾ 1
-```c
-룺["h","e","l","l","o"]
-["o","l","l","e","h"]
-```
-
-ʾ 2
-```c
-룺["H","a","n","n","a","h"]
-["h","a","n","n","a","H"]
-```
-
-
-
-**ο룺**
-
-- ״̬ͨ
-- ִʱ: 572 ms, C# ύл 94.94% û
-- ڴ: 33.6 MB, C# ύл 5.05% û
-
-```c
-public class Solution {
- public void ReverseString(char[] s) {
- int i = 0;
- int j = s.Length-1;
- while (i < j)
- {
- char c = s[i];
- s[i] = s[j];
- s[j] = c;
- i++;
- j--;
- }
- }
-}
-```
-
----
-## Ŀ06ظַӴ
-
-> - ţ3
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
-
-һַҳвظַ **Ӵ** ijȡ
-
-**ʾ 1:**
-
-```c
-: "abcabcbb"
-: 3
-: ΪظַӴ "abc"䳤Ϊ 3
-```
-
-**ʾ 2:**
-
-```c
-: "bbbbb"
-: 1
-: ΪظַӴ "b"䳤Ϊ 1
-```
-
-**ʾ 3:**
-```c
-: "pwwkew"
-: 3
-: ΪظַӴ "wke"䳤Ϊ 3
- ע⣬Ĵ𰸱 Ӵ ijȣ"pwke" һУӴ
-```
-
-**˼·**
-
-̬滮˼·ǰÿλΪֹλãظӴijȣ֮Щȵֵɡ
-
-λ`index`ظӴijΪ`result[index] = min{k1,k2}``k1 = result[index-1] + 1``k2`Ϊ`index`λǰֱ`index`λõַ`index=0`ΪֹӴȡ
-
-
-**ο룺**
-
-- ִнͨ
-- ִʱ96 ms, C# ύл 82.81% û
-- ڴģ25.2 MB, C# ύл 25.52% û
-
-```c
-public class Solution
-{
- public int LengthOfLongestSubstring(string s)
- {
- if (string.IsNullOrEmpty(s))
- return 0;
- int[] result = new int[s.Length];
- result[0] = 1;
-
- for (int i = 1; i < s.Length; i++)
- {
- int count = GetLength(i, s);
- result[i] = result[i-1] < count ? result[i-1]+1 : count;
- }
- return result.Max();
- }
- private int GetLength(int index,string s)
- {
- char c = s[index];
- int result = 1;
- for (int i = index-1; i >= 0; i--)
- {
- if (s[i] != c)
- result += 1;
- else
- break;
- }
- return result;
- }
-}
-```
-
----
-## Ŀ07Ӵ
-
-> - ţ5
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/longest-palindromic-substring/
-
-
-һַ sҵ s ĻӴԼ s Ϊ 1000
-
-ʾ 1
-```c
-: "babad"
-: "bab"
-ע: "aba" ҲһЧ𰸡
-```
-
-ʾ 2
-```c
-: "cbbd"
-: "bb"
-```
-
-ʾ 3
-```c
-: "a"
-: "a"
-```
-
-**˼·** ö̬滮ķ
-
-һͷַͬ磬abaǻģabcǡ
-
-̬滮㷨ηƣ˼Ҳǽֽɸ⣬⣬ȻЩĽõԭĽ⡣
-
-ηͬǣʺö̬滮⣬ֽõǻģһӽεǽһӽεĽĻϣнһ⣩÷η⣬ֽõĿ̫࣬Щⱻظ˺ܶΡܹѽĴ𰸣ҪʱҳõĴ𰸣ͿԱظ㣬ʡʱ
-
-ǿһ¼ѽĴ𰸡ܸԺǷõֻҪͽСǶ̬滮Ļ˼·
-
-Ķ̬滮㷨ֶǾͬʽ
-
-ʹüǺ `s[l, r]` ʾԭʼַһӴ`l``r` ֱұֵ߽ʹաұʾұ߽ȡ
-
-`dp[l, r]` ʾӴ `s[l, r]`Ҷ˵㣩ǷɻĴһά顣
-
-- Ӵֻ 1 ַһǻӴ
-- Ӵ 2 ַʱ`s[l, r]` һĴôĴ߸һַԵĻӴ `s[l + 1, r - 1]` ҲһǻĴ
-
-ʣ `s[l] == s[r]` ʱ`dp[l, r]`ֵ `dp[l + 1, r - l]` ﻹҪٶһ㣺ԭַȥұ߽硱Ӵı߽
-
-- ԭַԪظΪ 3 ʱұ߽ȣôȥԺֻʣ 1 ַһǻĴԭַҲһǻĴ
-- ԭַԪظΪ 2 ʱұ߽ȣôȥԺֻʣ 0 ַȻԭַҲһǻĴ
-
-ϣһַұ߽ȣжΪֻ¶֮һɣ
-- ȥұ߽Ժַ䣬`s[l + 1, r - 1]`Ԫ2`r - l <= 2`
-- ȥұ߽ԺַǻĴ`dp[l + 1, r - 1] == true`
-
-
-
-**ο**
-
-- ״̬ͨ
-- ִʱ: 232 ms, C# ύл 46.79% û
-- ڴ: 40.9 MB, C# ύл 5.43% û
-
-
-```c
-public class Solution {
- public string LongestPalindrome(string s)
- {
- if (string.IsNullOrEmpty(s))
- return string.Empty;
- int len = s.Length;
- if (len == 1)
- return s;
- int longestPalindromelen = 1;
- string longestPalindromeStr = s.Substring(0, 1);
- bool[,] dp = new bool[len, len];
-
- for (int r = 1; r < len; r++)
- {
- for (int l = 0; l < r; l++)
- {
- if (s[r] == s[l] && (r - l <= 2 || dp[l + 1, r - 1] == true))
- {
- dp[l, r] = true;
- if (longestPalindromelen < r - l + 1)
- {
- longestPalindromelen = r - l + 1;
- longestPalindromeStr = s.Substring(l, r - l + 1);
- }
- }
- }
- }
- return longestPalindromeStr;
- }
-}
-```
-
-
----
-## Ŀ08ַ
-
-> - ţ43
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/multiply-strings/
-
-
-ַʽʾķǸ`num1``num2``num1``num2`ij˻ǵij˻ҲʾΪַʽ
-
-ʾ 1:
-```c
-: num1 = "2", num2 = "3"
-: "6"
-```
-
-ʾ 2:
-```c
-: num1 = "123", num2 = "456"
-: "56088"
-```
-
-
-
-ʾ 3:
-```c
-: num1 = "498828660196", num2 = "840477629533"
-: "419254329864656431168468"
-```
-
-
-˵
-
-- `num1``num2`ijС110
-- `num1``num2`ֻ 0-9
-- `num1``num2`㿪ͷ 0
-- ʹκαĴͣ BigIntegerֱӽתΪ
-
-
-**ο**
-
-- ״̬ͨ
-- ִʱ132 ms, C# ύл 94.74% û
-- ڴģ24.1 MB, C# ύл 31.82% û
-
-```c
-public class Solution {
- public string Multiply(string num1, string num2) {
- if (num1 == "0" || num2 == "0")
- return "0";
- int len1 = num1.Length;
- int len2 = num2.Length;
- int len = len1 + len2;
- int[] temp = new int[len];
-
- for (int i = len2 - 1; i >= 0; i--)
- {
- int k = len2 - i;
- int b = num2[i] - '0';
- for (int j = len1 - 1; j >= 0; j--)
- {
- int a = num1[j] - '0';
- int c = a*b;
-
- temp[len - k] += c%10;
- if (temp[len - k] >= 10)
- {
- temp[len - k] = temp[len - k]%10;
- temp[len - k - 1]++;
- }
-
- temp[len - k - 1] += c/10;
- if (temp[len - k - 1] >= 10)
- {
- temp[len - k - 1] = temp[len - k - 1]%10;
- temp[len - k - 2]++;
- }
- k++;
- }
- }
-
- StringBuilder sb = new StringBuilder();
- int s = temp[0] == 0 ? 1 : 0;
- while (s < len)
- {
- sb.Append(temp[s]);
- s++;
- }
- return sb.ToString();
- }
-}
-```
-
-
-
-
-
-
----
-## Ŀ09ʽƥ
-
-> - ţ10
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/regular-expression-matching/
-
-һַ`s`һַ`p`ʵһ֧ '.' '*' ʽƥ䡣
-
-```c
-'.' ƥⵥַ
-'*' ƥǰһԪ
-```
-
-νƥ䣬Ҫ **** ַ`s`ģDzַ
-
-**˵:**
-
-- `s`Ϊգֻ a-z Сдĸ
-- `p`Ϊգֻ a-z СдĸԼַ '.' '*'
-
-**ʾ 1:**
-
-```c
-:
-s = "aa"
-p = "a"
-: false
-: "a" ƥ "aa" ַ
-```
-**ʾ 2:**
-
-```c
-:
-s = "aa"
-p = "a*"
-: true
-: Ϊ '*' ƥǰһԪ, ǰԪؾ 'a'ˣַ "aa" ɱΪ 'a' ظһΡ
-```
-
-**ʾ 3:**
-
-```c
-:
-s = "ab"
-p = ".*"
-: true
-: ".*" ʾƥ'*'ַ'.'
-```
-
-**ʾ 4:**
-
-```c
-:
-s = "aab"
-p = "c*a*b"
-: true
-: Ϊ '*' ʾ 'c' Ϊ 0 , 'a' ظһΡ˿ƥַ "aab"
-```
-
-**ʾ 5:**
-
-```c
-:
-s = "mississippi"
-p = "mis*is*p*."
-: false
-```
-
-**˼·**ݷ
-
-ƥ˼·ʵDzϵؼ`s``p`ĿƥײֱһַΪյʱóۡ
-
-ַֻͨƥ䣬Ƚϼɣ
-
-```c
-if (s[i] == p[i])
-```
-
-ʽַpֻһ"."һǣȻǰȽϼ
-
-```c
-if (s[i] == p[i] || p[i] == '.')
-```
-
-ʵʱҪжַȺַпյIJ
-
-ǣ"*"ַҪpĵiԪصһԪǺʱ
-
-- `i`ԪҪ0ΣǾͱ`s`䣬`p`ļԪأ`IsMatch``sbcpa*bc`Ǿͱ`s`䣬`p`"a*"`IsMatch(s:bc,p:bc)`
-- `i`ԪҪһλΣȱȽ`i`Ԫغ`s`Ԫأ`p`䣬`s`Ԫأ`IsMatch``saabbpa*bb`ͱ`p`䣬`s`Ԫأ`IsMatch(s:abb,p:a*bb)`
-
-ʱһЩҪ˼`sabbpa*abb`ַʽ
-
-- ڶȽ`i`Ԫغ`s`ԪأȾͻ`s`ַ`IsMatch(s:bb,p:a*abb)`ڰһȥ`p`Ԫأ`IsMatch(s:bb,p:abb)`յ`false`
-- ֱӰһȥ`p`Ԫأ`IsMatch(s:abb,p:abb)`յ`true`
-
-˵һֱὫеһߣǷڿƥ
-
-
-
-
-**ο**
-
-- ִнͨ
-- ִʱ768 ms, C# ύл 10.69% û
-- ڴģ25.6 MB, C# ύл 5.00% û
-
-```c
-public class Solution
-{
- public bool IsMatch(string s, string p)
- {
- //pΪմsΪմƥɹsΪմƥʧܡ
- if (string.IsNullOrEmpty(p))
- return string.IsNullOrEmpty(s) ? true : false;
-
- //жspַǷƥ䣬עҪжsΪ
- bool headMatched = string.IsNullOrEmpty(s) == false
- && (s[0] == p[0] || p[0] == '.');
-
- if (p.Length >= 2 && p[1] == '*')
- {
- //pĵһԪصһԪ*ֱж
- return IsMatch(s, p.Substring(2)) ||
- (headMatched && IsMatch(s.Substring(1), p));
- }
- else if (headMatched)
- {
- //spַ
- return IsMatch(s.Substring(1), p.Substring(1));
- }
- else
- {
- return false;
- }
- }
-}
-```
-
-## Ŀ10ͨƥ
-
-
-> - ţ44
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/wildcard-matching/
-
-
-һַ(`s`) һַģʽ(`p`) ʵһ֧`'?'``'*'`ͨƥ䡣
-
-```
-'?' ƥκεַ
-'*' ƥַַ
-ַȫƥƥɹ
-```
-
-**˵:**
-
-- `s`Ϊգֻ`a-z`Сдĸ
-- `p`Ϊգֻ`a-z`СдĸԼַ`?``*`
-
-**ʾ 1:**
-
-```c
-:
-s = "aa"
-p = "a"
-: false
-: "a" ƥ "aa" ַ
-```
-**ʾ 2:**
-
-```c
-:
-s = "aa"
-p = "*"
-: true
-: '*' ƥַ
-```
-
-**ʾ 3:**
-
-```c
-:
-s = "cb"
-p = "?a"
-: false
-: '?' ƥ 'c', ڶ 'a' ƥ 'b'
-```
-
-**ʾ 4:**
-
-```c
-:
-s = "adceb"
-p = "*a*b"
-: true
-: һ '*' ƥַ, ڶ '*' ƥַ "dce".
-```
-
-**ʾ 5:**
-
-```c
-:
-s = "acdcb"
-p = "a*c?b"
-: false
-```
-
-**ʾ 6:**
-
-```c
-룺
-"abefcdgiescdfimde"
-"ab*cd?i*de"
-true
-```
-
-**ʾ 7:**
-
-```c
-룺
-"aaaa"
-"***a"
-true
-```
-
-
-**˼·**˫
-
-`i``j`ֱ`s``p`ĵһַ±꣬ʼΪ0`istart``jstart`ֱ`s``p``'*'`ƥλãʼΪ`-1`
-
-ַͨƥ˼·࣬ѾƥɹIJ־ͲٿˣҪ`i``j`ǵǰڱȽϵַƥ`'*'`ܻᱻظʹȥƥַҪ`istart``jstart`ֱ`s``p`ƥ`'*'`λá
-
-1. `i``j`ǵַȻ`j`ַ`'?'`ƥɹ"Ƴ"`i``j`Ԫأ`i``j`
-2. `j`ַ`'*'`Ȼƥɹ`istart``jstart`ֱ`i`Ԫغ`j`Ԫأ`j`
-3. ٷ`istart>-1`˵֮ǰƥ`'*'`Ϊ`'*'`ƥַҪٴƥ`'*'`ƥַƶ`i``istart`һַ`istart`±`i`Ԫأͬʱƶ`j``jstart`һַ
-4. 㣬ƥʧܣ`false`
-
-`s`еַжϣΪ`s`ΪգʱҪ`p`Ϊջ`p`ֻʣǺŵʱܳɹƥ䡣
-
-**ο**
-
-- ִнͨ
-- ִʱ92 ms, C# ύл 95.00% û
-- ڴģ25.7 MB, C# ύл 66.67% û
-
-```c
-public class Solution
-{
- public bool IsMatch(string s, string p)
- {
- //pΪմsΪմƥɹsΪմƥʧܡ
- if (string.IsNullOrEmpty(p))
- return string.IsNullOrEmpty(s) ? true : false;
-
- int i = 0, j = 0, istart = -1, jstart = -1, plen = p.Length;
-
- //жsַǷƥ
- while (i < s.Length)
- {
- //ƥɹԼƥʧܷfalse
- if (j < plen && (s[i] == p[j] || p[j] == '?'))
- {
- i++;
- j++;
- }
- else if (j < plen && p[j] == '*')
- {
- istart = i;
- jstart = j;
- j++;
- }
- else if (istart > -1)
- {
- i = istart + 1;
- istart = i;
- j = jstart + 1;
- }
- else
- {
- return false;
- }
- }
- //sеַжϣΪsΪ
- //ʱҪpΪջpֻʣǺŵʱܳɹƥ䡣
- //pʣĶ*Ƴʣ*
- while (j < plen && p[j] == '*')
- {
- j++;
- }
- return j == plen;
- }
-}
-```
-
diff --git a/DataStructureAndAlgorithm/16 Leetcode同步练习(六).md b/DataStructureAndAlgorithm/16 Leetcode同步练习(六).md
deleted file mode 100644
index edd67d6..0000000
--- a/DataStructureAndAlgorithm/16 Leetcode同步练习(六).md
+++ /dev/null
@@ -1,1054 +0,0 @@
-
-# Leetcodeͬϰ
-## Ŀ¼
-- Ŀ01ͬ
-- Ŀ02Գƶ
-- Ŀ03
-- Ŀ04 Pow(x, n)
-- Ŀ05Ӽ
-- Ŀ06ױ
-- Ŀ07
-- Ŀ08ǰ
-- Ŀ09
-- Ŀ10ĺ
-
----
-## Ŀ01ͬ
-
-> - ţ100
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/same-tree/
-
-дһǷͬ
-
-ڽṹͬҽڵֵͬΪͬġ
-
-**ʾ 1**:
-
-```
-: 1 1
- / \ / \
- 2 3 2 3
-
- [1,2,3], [1,2,3]
-
-: true
-```
-
-**ʾ 2**:
-
-```
-: 1 1
- / \
- 2 2
-
- [1,2], [1,null,2]
-
-: false
-```
-
-**ʾ 3**:
-```
-: 1 1
- / \ / \
- 2 1 1 2
-
- [1,2,1], [1,1,2]
-
-: false
-```
-
-**ο룺**
-
-- ִнͨ
-- ִʱ160 ms, C# ύл 5.85% û
-- ڴģ24 MB, C# ύл 6.67% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-
-public class Solution
-{
- public bool IsSameTree(TreeNode p, TreeNode q)
- {
- //ݹֹ
- if (p == null && q == null)
- return true;
-
- if (p != null && q != null && p.val == q.val)
- {
- return IsSameTree(p.left, q.left)
- && IsSameTree(p.right, q.right);
- }
- return false;
- }
-}
-```
-
----
-## Ŀ02Գƶ
-
-> - ţ101
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/symmetric-tree/
-
-һǷǾԳƵġ
-
-磬 `[1,2,2,3,4,4,3]` ǶԳƵġ
-
-```
- 1
- / \
- 2 2
- / \ / \
-3 4 4 3
-```
-
- `[1,2,2,null,3,null,3]` ǾԳƵ:
-
-```
- 1
- / \
- 2 2
- \ \
- 3 3
-```
-
-**ο룺**
-
-**һ֣õݹķ**
-
-- ִнͨ
-- ִʱ132 ms, C# ύл 16.67% û
-- ڴģ25.1 MB, C# ύл 5.17% û
-
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-
-//ԳƵĵݹ麯
-public class Solution
-{
- public bool IsSymmetric(TreeNode root)
- {
- return IsMirror(root, root);
- }
- private bool IsMirror(TreeNode t1, TreeNode t2)
- {
- if (t1 == null && t2 == null) return true;
- if (t1 == null || t2 == null) return false;
- return (t1.val == t2.val)
- && IsMirror(t1.left, t2.right)
- && IsMirror(t1.right, t2.left);
- }
-}
-```
-
-**ڶ֣öеķ**
-
-**˼·**öIJαķʽʵ֡
-
-- ִнͨ
-- ִʱ112 ms, C# ύл 70.93% û
-- ڴģ24.9 MB, C# ύл 5.17% û
-
-```c
-public class Solution
-{
- public bool IsSymmetric(TreeNode root)
- {
- if (root == null)
- return true;
-
- Queue nodes = new Queue();
- nodes.Enqueue(root.left);
- nodes.Enqueue(root.right);
- while (nodes.Count != 0)
- {
- TreeNode node1 = nodes.Dequeue();
- TreeNode node2 = nodes.Dequeue();
-
- if (node1 == null && node2 == null)
- continue;
- if (node1 == null || node2 == null)
- return false;
- if (node1.val != node2.val)
- return false;
- nodes.Enqueue(node1.left);
- nodes.Enqueue(node2.right);
- nodes.Enqueue(node1.right);
- nodes.Enqueue(node2.left);
- }
- return true;
- }
-}
-```
-
----
-## Ŀ03
-
-> - ţ104
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
-
-
-һҳȡ
-
-Ϊڵ㵽ԶҶӽڵ·ϵĽڵ
-
-˵: ҶӽڵָûӽڵĽڵ㡣
-
-**ʾ**
-
- [3,9,20,null,null,15,7]
-
-```c
- 3
- / \
- 9 20
- / \
- 15 7
-```
-
- 3
-
-**ο룺**
-
-**һ֣öʵֲα˼·**
-
-- ִнͨ
-- ִʱ108 ms, C# ύл 88.13% û
-- ڴģ25.5 MB, C# ύл 5.97% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public int MaxDepth(TreeNode root)
- {
- if (root == null)
- return 0;
-
- Queue q = new Queue();
- int deep = 0;
- q.Enqueue(root);
-
- while (q.Count != 0)
- {
- deep++;
- int count = 0;
- int size = q.Count;
-
- while (count < size)
- {
- TreeNode node = q.Dequeue();
- count++;
-
- if (node.left != null)
- q.Enqueue(node.left);
- if (node.right != null)
- q.Enqueue(node.right);
- }
- }
- return deep;
- }
-}
-```
-
-
-
-**ڶ֣õݹ**
-
-**˼·**ݹֱȣӵԭвϣеֵ
-
-- ִнͨ
-- ִʱ132 ms, C# ύл 16.62% û
-- ڴģ25.5 MB, C# ύл 6.06% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public int MaxDepth(TreeNode root)
- {
- if (root == null)
- return 0;
- int llen = 1;
- int rlen = 1;
- if (root.left != null)
- {
- llen += MaxDepth(root.left);
- }
- if (root.right != null)
- {
- rlen += MaxDepth(root.right);
- }
- return llen > rlen ? llen : rlen;
- }
-}
-```
----
-## Ŀ04 Pow(x, n)
-
-> - ţ50
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/powx-n/
-
-
-ʵ `pow(x, n)` x n ݺ
-
-**ʾ 1:**
-
-```c
-: 2.00000, 10
-: 1024.00000
-```
-
-**ʾ 2:**
-```c
-: 2.10000, 3
-: 9.26100
-```
-
-**ʾ 3:**
-```c
-: 2.00000, -2
-: 0.25000
-: 2-2 = 1/22 = 1/4 = 0.25
-```
-
-**ʾ 4:**
-```c
-: 1.00000, -2147483648
-: 1.00000
-```
-
-**˵:**
-
-- -100.0 < x < 100.0
-- n 32 λзֵΧ [?2^31, 2^31 ? 1]
-
-
-**˼·**ÿݷ
-
-Ҫ`a^b`ô`b`ԲɶƱʾ統`b = 5`ʱ5Ķ0101`5 = 2^30 + 2^21 + 2^10 + 2^01`ˣǽ`a^5`תΪ `a^(2^30 + 2^21 + 2^10 + 2^01)``a^(2^0) a^(2^2)`
-
-
-
-
-2ݣȻx2ݴηٰnɶƣѶƵжӦλ1ֵ͵õ˽Ϊ **ݷ**
-
-
-**ο**
-
-- ִнͨ
-- ִʱ56 ms, C# ύл 51.87% û
-- ڴģ15.1 MB, C# ύл 50.00% û
-
-```c
-public class Solution
-{
- public double MyPow(double x, int n)
- {
- int neg = n < 0 ? -1 : 1;
- long g = Math.Abs((long)n);
-
- double[] d = new double[32];
- d[0] = x;
- for (int i = 1; i < 32; i++)
- {
- d[i] = d[i - 1] * d[i - 1];
- }
-
- double result = 1.0d;
- for (int i = 0; i < 32; i++)
- {
- int mask = 1 << i;
- if ((mask & g) != 0)
- {
- result *= d[i];
- }
- }
- return neg != -1 ? result : 1.0 / result;
- }
-}
-```
----
-## Ŀ05Ӽ
-
-> - ţ78
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/subsets/
-
-
-һ**ظԪ** numsظпܵӼݼ
-
-˵⼯ܰظӼ
-
-ʾ:
-```c
-: nums = [1,2,3]
-:
-[
- [3],
- [1],
- [2],
- [1,2,3],
- [1,3],
- [2,3],
- [1,2],
- []
-]
-```
-
-**ο**
-
-**һ֣ݷ**
-
-nums[i]ΪʼҺֵҪǰһֵظ
-
-
-
-- ״̬ͨ
-- ʱ: 356 ms, C# ύл 92.31% û
-- ڴ: 29.2 MB, C# ύл 6.67% û
-
-```c
-public class Solution
-{
- private IList> _result;
-
- public IList> Subsets(int[] nums)
- {
- _result = new List>();
- int len = nums.Length;
-
- if (len == 0)
- {
- return _result;
- }
- IList item = new List();
- Find(nums, 0, item);
- return _result;
- }
-
- private void Find(int[] nums, int begin, IList item)
- {
- // ע⣺Ҫ new һ
- _result.Add(new List(item));
-
- if (begin == nums.Length)
- return;
-
- for (int i = begin; i < nums.Length; i++)
- {
- item.Add(nums[i]);
- Find(nums, i + 1, item);
-
- // ⣬״̬ڵݹɺҪ
- item.RemoveAt(item.Count - 1);
- }
- }
-}
-```
-
-**ڶ֣Ӽչ**
-
-- ״̬ͨ
-- ִʱ: 352 ms, C# ύл 94.51% û
-- ڴ: 29.2 MB, C# ύл 6.67% û
-
-```c
-public class Solution
-{
- public IList> Subsets(int[] nums)
- {
- IList> result = new List>();
- IList item = new List();
- result.Add(item);
- for (int i = 0; i < nums.Length; i++)
- {
- for (int j = 0, len = result.Count; j < len; j++)
- {
- item = new List(result[j]);
- item.Add(nums[i]);
- result.Add(item);
- }
- }
- return result;
- }
-}
-```
-
-**֣λ**
-
-**˼·** ϵ˼·
-
-`{1,2,3}`Ϊ`2^3`Ӽ
-
-```c
-000 -> []
-100 -> [1]
-101 -> [1,3]
-110 -> [1,2]
-111 -> [1,2,3]
-...
-```
-
-- ״̬ͨ
-- ִʱ: 348 ms, C# ύл 97.80% û
-- ڴ: 29.5 MB, C# ύл 6.67% û
-
-```c
-public class Solution
-{
- public IList> Subsets(int[] nums)
- {
- IList> result = new List>();
- int count = nums.Length;
-
- for (int i = 0; i < 1 << count; i++)
- {
- IList item = new List();
- for (int j = 0; j < count; j++)
- {
- int mask = 1 << j;
- if ((mask & i) != 0)
- item.Add(nums[j]);
- }
- result.Add(item);
- }
- return result;
- }
-}
-```
-
----
-## Ŀ06ױ
-
-> - ţ89
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/gray-code/
-
-ױһϵͳڸϵͳУֵһλIJ졣
-
-һλķǸ nӡױСױб 0 ͷ
-
-ʾ 1:
-```c
-: 2
-: [0,1,3,2]
-:
-00 - 0
-01 - 1
-11 - 3
-10 - 2
-
-ڸ nױвΨһ
-磬[0,2,3,1] ҲһЧĸױС
-
-00 - 0
-10 - 2
-11 - 3
-01 - 1
-```
-
-ʾ 2:
-```c
-: 0
-: [0]
-: Ƕױб 0 ͷ
- λΪ n ĸױУ䳤Ϊ 2^n
- n = 0 ʱΪ 2^0 = 1
- ˣ n = 0 ʱױΪ [0]
-```
-
-**˼·**
-
-
-
-
- n λƵ n+1 λʱn+1 λ n λͬʱ n λڸλһλ 1 γɵһһҪǰһС
-
-**ο**
-
-- ״̬ͨ
-- 12 / 12 ͨ
-- ִʱ: 296 ms, C# ύл 95.83% û
-- ڴ: 24.8 MB, C# ύл 16.67% û
-
-```c
-public class Solution
-{
- public IList GrayCode(int n)
- {
- IList lst = new List();
- lst.Add(0);
- for (int i = 1; i <= n; i++)
- {
- for (int j = lst.Count - 1; j >= 0; j--)
- {
- int item = lst[j] + (1 << i - 1);
- lst.Add(item);
- }
- }
- return lst;
- }
-}
-```
-
-
----
-## Ŀ07
-
-
-
-> - ţ236
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/
-
-һ, ҵָڵȡ
-
-ٶȰٿȵĶΪи T pqȱʾΪһ x x pq x ȾܴһڵҲԼ
-
-磬¶: root = [3,5,1,6,2,0,8,null,null,7,4]
-
-
-
-ʾ 1:
-```c
-: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
-: 3
-: ڵ 5 ͽڵ 1 ǽڵ 3
-```
-
-ʾ 2:
-```c
-: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
-: 5
-: ڵ 5 ͽڵ 4 ǽڵ 5ΪݶȽڵΪڵ㱾
-```
-
-˵:
-
-- нڵֵΨһġ
-- pq ΪͬڵҾڸĶС
-
-
-**ο**
-
-**˼·**õݹ
-
-- ״̬ͨ
-- ִʱ: 132 ms, C# ύл 96.10% û
-- ڴ: 27.5 MB, C# ύл 20.00% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-
-public class Solution
-{
- public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q)
- {
- return Find(root, p, q);
- }
-
- private TreeNode Find(TreeNode current, TreeNode p, TreeNode q)
- {
- if (current == null || current == p || current == q)
- return current;
- TreeNode left = Find(current.left, p, q);
- TreeNode right = Find(current.right, p, q);
- if (left != null && right != null)
- return current;
- return left != null ? left : right;
- }
-}
-```
-
-
-
----
-## Ŀ08ǰ
-
-> - ţ144
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/binary-tree-preorder-traversal/
-
-
-һ ǰ
-
-**ʾ:**
-
-
-```c
-: [1,null,2,3]
- 1
- \
- 2
- /
- 3
-
-: [1,2,3]
-```
-
-
-: ݹ㷨ܼͨ㷨
-
-
-**ο**
-
-**һ֣ջ**
-
-- ִнͨ
-- ִʱ276 ms, C# ύл 84.15% û
-- ڴģ29.9 MB, C# ύл 5.00% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public IList PreorderTraversal(TreeNode root)
- {
- IList lst = new List();
- Stack stack = new Stack();
- while (stack.Count != 0 || root != null)
- {
- if (root != null)
- {
- stack.Push(root);
- lst.Insert(lst.Count, root.val);
- root = root.left;
- }
- else
- {
- TreeNode node = stack.Pop();
- root = node.right;
- }
- }
- return lst;
- }
-}
-```
-
-**ڶ֣õݹ**
-
-- ִнͨ
-- ִʱ280 ms, C# ύл 79.27% û
-- ڴģ29.8 MB, C# ύл 5.00% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public IList PreorderTraversal(TreeNode root)
- {
- IList lst = new List();
- PreOrder(root, lst);
- return lst;
- }
- private void PreOrder(TreeNode node, IList lst)
- {
- if (node == null)
- return;
-
- lst.Add(node.val);
- PreOrder(node.left, lst);
- PreOrder(node.right, lst);
- }
-}
-```
-
-
----
-## Ŀ09
-
-> - ţ94
-> - Ѷȣе
-> - https://leetcode-cn.com/problems/binary-tree-inorder-traversal/
-
-һ
-
-**ʾ:**
-
-```c
-: [1,null,2,3]
- 1
- \
- 2
- /
- 3
-
-: [1,3,2]
-```
-
-: ݹ㷨ܼͨ㷨
-
-
-**ο룺**
-
-**һ֣ջ**
-
-- ִнͨ
-- ִʱ284 ms, C# ύл 53.59% û
-- ڴģ30 MB, C# ύл 6.67% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public IList InorderTraversal(TreeNode root)
- {
- IList lst = new List();
- Stack stack = new Stack();
- while (stack.Count != 0 || root != null)
- {
- if (root != null)
- {
- stack.Push(root);
- root = root.left;
- }
- else
- {
- TreeNode node = stack.Pop();
- lst.Add(node.val);
- root = node.right;
- }
- }
- return lst;
- }
-}
-```
-
-
-
-**ڶ֣ʹõݹ**
-
-- ִнͨ
-- ִʱ264 ms, C# ύл 99.16% û
-- ڴģ29.8 MB, C# ύл 6.67% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public IList InorderTraversal(TreeNode root)
- {
- IList lst = new List();
- MidOrder(root, lst);
- return lst;
- }
- private void MidOrder(TreeNode node, IList lst)
- {
- if (node == null)
- return;
- MidOrder(node.left, lst);
- lst.Add(node.val);
- MidOrder(node.right, lst);
- }
-}
-```
-
-
-
----
-## Ŀ10ĺ
-
-> - ţ145
-> - Ѷȣ
-> - https://leetcode-cn.com/problems/binary-tree-postorder-traversal/
-
-
-һ
-
-**ʾ:**
-
-
-```c
-: [1,null,2,3]
- 1
- \
- 2
- /
- 3
-
-: [3,2,1]
-```
-
-
-: ݹ㷨ܼͨ㷨
-
-
-**ο**
-
-
-**һ֣ջ**
-
-ǰ˳Ϊ -> ->
-
-˳Ϊ -> ->
-
-1ǽǰнڵβΪڵͷ
-
-ôͱΪˣ -> ->
-
-2ǽ˳ɴΪҵ1
-
-ôͱΪˣ -> ->
-
-պǺ˳
-
-˼·Ǵʽ£
-
-һǰУڵдĴ룬βΪ
-
-ڶǰУÿȲ鿴ڵٲ鿴ҽڵΪȲ鿴ҽڵٲ鿴ڵ
-
-- ִнͨ
-- ִʱ272 ms, C# ύл 98.15% û
-- ڴģ30 MB, C# ύл 6.90% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public IList PostorderTraversal(TreeNode root)
- {
- IList lst = new List();
- Stack stack = new Stack();
- while (stack.Count != 0 || root != null)
- {
- if (root != null)
- {
- stack.Push(root);
- lst.Insert(0, root.val);
- root = root.right;
- }
- else
- {
- TreeNode node = stack.Pop();
- root = node.left;
- }
- }
- return lst;
- }
-}
-```
-
-**ڶ֣õݹ**
-
-- ִнͨ
-- ִʱ276 ms, C# ύл 89.81% û
-- ڴģ30 MB, C# ύл 6.90% û
-
-```c
-/**
- * Definition for a binary tree node.
- * public class TreeNode {
- * public int val;
- * public TreeNode left;
- * public TreeNode right;
- * public TreeNode(int x) { val = x; }
- * }
- */
-public class Solution
-{
- public IList PostorderTraversal(TreeNode root)
- {
- IList lst = new List();
- PostOrder(root, lst);
- return lst;
- }
- private void PostOrder(TreeNode node, IList lst)
- {
- if (node == null)
- return;
-
- PostOrder(node.left, lst);
- PostOrder(node.right, lst);
- lst.Add(node.val);
- }
-}
-```
-
-
diff --git a/DataStructureAndAlgorithm/精选练习50题.md b/DataStructureAndAlgorithm/精选练习50题.md
new file mode 100644
index 0000000..beae88f
--- /dev/null
+++ b/DataStructureAndAlgorithm/精选练习50题.md
@@ -0,0 +1,398 @@
+# ѡϰ50
+
+**01ڼеıʾΪݵ______**
+- A洢ṹ
+- Bṹ
+- C˳ṹ
+- Dṹ
+
+**02һ㷨______**
+- A
+- Bȷ
+- C
+- D
+
+**03¶ʽ洢ṹд______**
+- AڵĽ㣬ϲ
+- Bͨ㣬ֱȷiĴ洢ַ
+- C롢ɾ㣬شƶ
+- Dָ洢ܶС˳洢ṹ
+
+**04ԱУȷ______**
+- AԱ˳洢ʱռһƬĴ洢Ԫ
+- BԱʽ洢ʱҪռһƬĴ洢Ԫ
+- CԱ˳洢ʱڽвɾ
+- DԱʽ洢ʱڽвɾ
+
+
+
+**05һУPָ㲻㣬P֮Sָ㣬ִ______**
+- AS.Next=P; P.Next=S;
+- BS.Next=P.Next; P.Next=S;
+- CS.Next=P.Next; P =S;
+- DP.Next=S; S.Next=P;
+
+
+
+**06˫УɾPָĽ㣬ִ______**
+- AP.Next.Prior=P.Prior; P.Prior.Next=P.Next;
+- BP.Next.Prior=P.Prior; P.Prior=P.Next;
+- CP.Prior.Next=P; P.Prior =P.Prior.Prior;
+- DP.Prior=P.Next.Next; P.Next=P.Prior.Prior;
+
+
+
+**07һΪn˳УڵiԪأ1in+1֮ǰһԪʱƶ______Ԫء**
+- An-i
+- Bn-i+1
+- Cn-i-1
+- Di
+
+
+
+**08ջص______**
+- AȽȳ
+- Bȳ
+- Cڳ
+- Dڽ
+
+
+
+**09ӵص______**
+- AȽȳ
+- Bȳ
+- Cڳ
+- Dڽ
+
+
+
+**10ջͶеĹͬ______**
+- AȽ
+- BȽȳ
+- Cֻڶ˵㴦ɾԪ
+- Dûйͬ
+
+
+
+**11______ջĻ㡣**
+- AɾջԪ
+- BɾջԪ
+- CжջǷΪ
+- DջΪջ
+
+
+
+**12ջSͶQijʼ״̬ΪգԪabcdefͨջSһԪسջQ6Ԫسӵ˳bdcfeaջSӦ______**
+- A2
+- B3
+- C4
+- D5
+
+
+
+**131234ĸԪذ˳ջܵijջ˳Ϊ______**
+- A1234
+- B2341
+- C1432
+- D3142
+
+
+
+**14ڽӡ֮ٶȲƥʱͨһӡݻҪдûӡӸûȡݴӡûӦһ______ṹ**
+- Aջ
+- B
+- C
+- DԱ
+
+**15ʾԱŵ______**
+- Aȡ
+- BѵĴ洢ռ˳洢
+- Cڲɾ
+- DԪص˳˳ͬ
+
+
+
+**16˳洢Ա䳤ΪnκλϲɾǵȸʵġһԪʱƽҪƶе______Ԫء**
+- An/2
+- B(n+1)/2
+- C(n-1)/2
+- Dn
+
+
+
+**17˳洢Ա䳤ΪnκλϲɾǵȸʵġɾһԪʱƽҪƶе______Ԫء**
+- An/2
+- B(n+1)/2
+- C(n-1)/2
+- Dn
+
+
+
+**18ѭҪŵ______**
+- AҪͷָˡ
+- B֪ijλúܹҵֱǰ
+- Cڽв롢ɾʱܸõı֤Ͽ
+- Dӱеɨ赽
+
+
+**19ַPQQPӴQP״γֵλΪӴQPλõ㷨Ϊ______**
+- A
+- Bƥ
+- CӴ
+- D
+
+
+
+**20ijάA±ķΧ08±ķΧ04еԪڵ4ֽڴ洢洢ֽڱ롣洢ԪA[00]ĵһֽڵĵַ0洢AһԪصһֽڵĵַ______**
+- A175
+- B86
+- C68
+- D176
+
+
+
+**21______ǡabcd321ABCDӴ**
+- Aabcd
+- B321AB
+- CabcABC
+- D21AB
+
+
+
+**22֪һöǰзֱΪABDEGCFHDBGEACHFöĺΪ______**
+- AGEDHFBCA
+- BACBFEDHG
+- CABCDEFGH
+- DDGEBHFCA
+
+**23֪ijǰΪABDCEпǶԸöõ______**
+- ABCADE
+- BCBADE
+- CBDAEC
+- DBEACD
+
+
+
+
+
+**24ĺDABECDEBAC˶ǰ______**
+- AACBED
+- BDECAB
+- CDEABC
+- DCEDBA
+
+
+
+**25ĶΪ4жΪ1234ĽֱΪ5321ôҶӽĸ______**
+- A8
+- B10
+- C11
+- D12
+
+
+
+**26漸Ŵ뼯Уǰ______**
+- A{0101101111}
+- B{11100011010001}
+- C{0001001101000}
+- D{BCAAACABAABBABC}
+
+
+
+**27ĻԿԷΪǰͺĻԿɷΪǰֱǰתõĶΪӦĶȷ______**
+- AǰӦĶǰͬ
+- BĺӦĶͬ
+- CǰӦĶͬ
+- D϶
+
+
+
+**28nϺеΪ______**
+- A2n
+- Bn-1
+- Cn+1
+- Dn
+
+
+
+**296ͼӦ______߲ȷһǿͨͼ**
+- A5
+- B6
+- C7
+- D8
+
+
+
+**30һnͨͼ______ߡ**
+- An-1
+- Bn
+- Cn/2
+- Dn+1
+
+
+
+**31ͼĽΪnͼ______ߡ**
+- An-1
+- Bn(n-1)/2
+- Cn(n+1)/2
+- Dn*n
+
+
+
+**32ͼĽΪnͼ______ߡ**
+- An-1
+- Bn(n-1)
+- Cn(n-1)/2
+- Dn*n
+
+
+
+**33һnͨͼͨΪ______**
+- A0
+- B1
+- Cn
+- Dn+1
+
+
+
+**34һͼаkͨн㣬______㷨**
+- Ak
+- B1
+- Ck-1
+- Dk+1
+
+
+
+**35ͼGУ$v_i$$v_j$֮ǰֵܳ______**
+- AGл $< v_i,v_j>$
+- BGһ$v_i$$v_j$·
+- CGûл$< v_i,v_j>$
+- DGһ$v_j$$v_i$·
+
+
+
+**36һõݽṹؼ______һѡ**
+- A167231239453
+- B945331721653
+- C165323943172
+- D163123945372
+
+
+
+**37вǶѵ______**
+- A10085987780608240201066
+- B10098858280776660402010
+- C10204060667780828598100
+- D10085407780606698821020
+
+
+
+**38Թؼ{72737123941656876103}ѣӼֵΪ______Ľ㿪ʼ**
+- A103
+- B72
+- C94
+- D23
+
+
+
+
+**39㷨Ƚ¼ЩҪļ¼λãֱźΪֹ______**
+- A
+- B
+- Cѡ
+- D
+
+
+
+**40㷨аѵi¼뵽ǰźõļ¼Уʹǰi¼Ҫ______**
+- A
+- B
+- Cѡ
+- D
+
+
+
+**41㷨ÿδȫδļ¼ѡСļ¼źõļ¼ĩβ______**
+- A
+- B
+- Cѡ
+- D
+
+
+
+**42У______ſִеһ˿õС**
+- A{8618} 19 {161050}
+- B{648} 18 {81193618}
+- C{8112} 36 {998169}
+- D{234} 89 {789868}
+
+
+
+**438Ԫص{4938659776132750}С˳ֱѡһ˵______**
+- A1338659776492750
+- B1327384950657697
+- C9776655049382713
+- D1338655076492797
+
+
+
+**44{72737123941656876103}չѵķʽСһ˵______**
+
+- A10394717673165682372
+- B72947176731656823103
+- C94767172731656823103
+- D23767172731656894103
+
+**45{72737123941656876103}delta=5Сϣһ˵______**
+
+- A10394717673165682372
+- B16568237371767294103
+- C16716823947273576103
+- D16568239472737176103
+
+
+
+
+**46ԱжֲʱҪԱ______**
+- A˳ʽ洢
+- Bʽʽ洢
+- C˳ʽ洢ҽ㰴ؼ
+- Dʽʽ洢ҽ㰴ؼ
+
+
+
+**47˳{3681012151618212530}Уöַҹؼ11ĹؼȽϴΪ______**
+- A2
+- B3
+- C4
+- D5
+
+
+
+**48˳{2571014151823354152}Уöַҹؼ18ĹؼȽϴΪ______**
+- A2
+- B3
+- C4
+- D5
+
+
+
+**4919Ԫص¼RecordöֲңKey=Record[3]ıȽе±꣨±0ʼΪ______**
+- A953
+- B9523
+- C9423
+- D94123
+
+
+
+**50______ԵõС**
+- Aǰ
+- B
+- C
+- Dα
+
+
+
+
+
+
diff --git a/IntroductionToNumpy/Task06 输入输出.md b/IntroductionToNumpy/Task06 输入输出.md
new file mode 100644
index 0000000..b7e7a4e
--- /dev/null
+++ b/IntroductionToNumpy/Task06 输入输出.md
@@ -0,0 +1,396 @@
+# 输入和输出
+
+
+
+## 1. numpy 二进制文件
+
+`save()`、`savez()`和`load()`函数以 numpy 专用的二进制类型(`.npy`、`.npz`)保存和读取数据,这三个函数会自动处理ndim、dtype、shape等信息,使用它们读写数组非常方便,但是`save()`和`savez()`输出的文件很难与其它语言编写的程序兼容。
+
+
+
+
+【函数】
+```python
+def save(file, arr, allow_pickle=True, fix_imports=True):
+```
+- `save()`函数:以`.npy`格式将数组保存到二进制文件中。
+- `.npy`格式:以二进制的方式存储文件,在二进制文件第一行以文本形式保存了数据的元信息(ndim,dtype,shape等),可以用二进制工具查看内容。
+
+
+
+【函数】
+```python
+def load(file, mmap_mode=None, allow_pickle=False, fix_imports=True, encoding='ASCII'):
+```
+
+- `load()`函数:从`.npy`、`.npz`或 pickled文件加载数组或pickled对象。
+- `mmap_mode: {None, ‘r+’, ‘r’, ‘w+’, ‘c’};`:读取文件的方式。
+- `allow_pickle=False`:允许加载存储在`.npy`文件中的pickled对象数组。
+- `fix_imports=True`:若为True,pickle将尝试将旧的python2名称映射到python3中使用的新名称。
+- `encoding='ASCII'`:制定编码格式,默认为“ASCII”。
+
+
+【例子】将一个数组保存到一个文件中。
+```python
+import numpy as np
+
+outfile = r'.\test.npy'
+np.random.seed(20200619)
+x = np.random.uniform(low=0, high=1,size = [3, 5])
+np.save(outfile, x)
+y = np.load(outfile)
+print(y)
+# [[0.01123594 0.66790705 0.50212171 0.7230908 0.61668256]
+# [0.00668332 0.1234096 0.96092409 0.67925305 0.38596837]
+# [0.72342998 0.26258324 0.24318845 0.98795012 0.77370715]]
+```
+
+【函数】
+```python
+def savez(file, *args, **kwds):
+```
+
+- `savez()`函数:以未压缩的`.npz`格式将多个数组保存到单个文件中。
+- `.npz`格式:以压缩打包的方式存储文件,可以用压缩软件解压。
+- `savez()`函数:第一个参数是文件名,其后的参数都是需要保存的数组,也可以使用关键字参数为数组起一个名字,非关键字参数传递的数组会自动起名为`arr_0, arr_1, …`。
+- `savez()`函数:输出的是一个压缩文件(扩展名为`.npz`),其中每个文件都是一个`save()`保存的`.npy`文件,文件名对应于数组名。`load()`自动识别`.npz`文件,并且返回一个类似于字典的对象,可以通过数组名作为关键字获取数组的内容。
+
+【例子】将多个数组保存到一个文件。
+```python
+import numpy as np
+
+outfile = r'.\test.npz'
+x = np.linspace(0, np.pi, 5)
+y = np.sin(x)
+z = np.cos(x)
+np.savez(outfile, x, y, z_d=z)
+data = np.load(outfile)
+np.set_printoptions(suppress=True)
+print(data.files)
+# ['z_d', 'arr_0', 'arr_1']
+
+print(data['arr_0'])
+# [0. 0.78539816 1.57079633 2.35619449 3.14159265]
+
+print(data['arr_1'])
+# [0. 0.70710678 1. 0.70710678 0. ]
+
+print(data['z_d'])
+# [ 1. 0.70710678 0. -0.70710678 -1. ]
+```
+
+用解压软件打开 test.npz 文件,会发现其中有三个文件:`arr_0.npy,arr_1.npy,z_d.npy`,其中分别保存着数组`x,y,z`的内容。
+
+
+---
+## 2. 文本文件
+`savetxt()`,`loadtxt()`和`genfromtxt()`函数用来存储和读取文本文件(如`.TXT`,`.CSV`等)。`genfromtxt()`比`loadtxt()`更加强大,可对缺失数据进行处理。
+
+
+【函数】
+```python
+def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n',header='', footer='', comments='# ', encoding=None):
+```
+- `fname`:文件路径
+- `X`:存入文件的数组。
+- `fmt='%.18e'`:写入文件中每个元素的字符串格式,默认'%.18e'(保留18位小数的浮点数形式)。
+- `delimiter=' '`:分割字符串,默认以空格分隔。
+
+```python
+def loadtxt(fname, dtype=float, comments='#', delimiter=None,
+ converters=None, skiprows=0, usecols=None, unpack=False,
+ ndmin=0, encoding='bytes', max_rows=None):
+```
+- `fname`:文件路径。
+- `dtype=float`:数据类型,默认为float。
+- `comments='#'`: 字符串或字符串组成的列表,默认为'#',表示注释字符集开始的标志。
+- `skiprows=0`:跳过多少行,一般跳过第一行表头。
+- `usecols=None`:元组(元组内数据为列的数值索引), 用来指定要读取数据的列(第一列为0)。
+- `unpack=False`:当加载多列数据时是否需要将数据列进行解耦赋值给不同的变量。
+
+
+【例】写入和读出TXT文件。
+```python
+import numpy as np
+
+outfile = r'.\test.txt'
+x = np.arange(0, 10).reshape(2, -1)
+np.savetxt(outfile, x)
+y = np.loadtxt(outfile)
+print(y)
+# [[0. 1. 2. 3. 4.]
+# [5. 6. 7. 8. 9.]]
+```
+
+test.txt文件如下:
+
+```python
+0.000000000000000000e+00 1.000000000000000000e+00 2.000000000000000000e+00 3.000000000000000000e+00 4.000000000000000000e+00
+5.000000000000000000e+00 6.000000000000000000e+00 7.000000000000000000e+00 8.000000000000000000e+00 9.000000000000000000e+00
+```
+
+
+【例子】写入和读出CSV文件。
+```python
+import numpy as np
+
+outfile = r'.\test.csv'
+x = np.arange(0, 10, 0.5).reshape(4, -1)
+np.savetxt(outfile, x, fmt='%.3f', delimiter=',')
+y = np.loadtxt(outfile, delimiter=',')
+print(y)
+# [[0. 0.5 1. 1.5 2. ]
+# [2.5 3. 3.5 4. 4.5]
+# [5. 5.5 6. 6.5 7. ]
+# [7.5 8. 8.5 9. 9.5]]
+```
+
+test.csv文件如下:
+```python
+0.000,0.500,1.000,1.500,2.000
+2.500,3.000,3.500,4.000,4.500
+5.000,5.500,6.000,6.500,7.000
+7.500,8.000,8.500,9.000,9.500
+```
+
+
+
+【函数】
+
+```python
+def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
+ skip_header=0, skip_footer=0, converters=None,
+ missing_values=None, filling_values=None, usecols=None,
+ names=None, excludelist=None,
+ deletechars=''.join(sorted(NameValidator.defaultdeletechars)),
+ replace_space='_', autostrip=False, case_sensitive=True,
+ defaultfmt="f%i", unpack=None, usemask=False, loose=True,
+ invalid_raise=True, max_rows=None, encoding='bytes'):
+```
+- `genfromtxt()`函数:从文本文件加载数据,并按指定方式处理缺少的值(是面向结构数组和缺失数据处理的。)。
+- `names=None`:设置为True时,程序将把第一行作为列名称。
+
+
+data.csv文件(不带缺失值)
+```python
+id,value1,value2,value3
+1,123,1.4,23
+2,110,0.5,18
+3,164,2.1,19
+```
+
+【例子】
+```python
+import numpy as np
+
+outfile = r'.\data.csv'
+x = np.loadtxt(outfile, delimiter=',', skiprows=1)
+print(x)
+# [[ 1. 123. 1.4 23. ]
+# [ 2. 110. 0.5 18. ]
+# [ 3. 164. 2.1 19. ]]
+
+x = np.loadtxt(outfile, delimiter=',', skiprows=1, usecols=(1, 2))
+print(x)
+# [[123. 1.4]
+# [110. 0.5]
+# [164. 2.1]]
+
+val1, val2 = np.loadtxt(outfile, delimiter=',', skiprows=1, usecols=(1, 2), unpack=True)
+print(val1) # [123. 110. 164.]
+print(val2) # [1.4 0.5 2.1]
+```
+
+
+【例子】
+```python
+import numpy as np
+
+outfile = r'.\data.csv'
+x = np.genfromtxt(outfile, delimiter=',', names=True)
+print(x)
+# [(1., 123., 1.4, 23.) (2., 110., 0.5, 18.) (3., 164., 2.1, 19.)]
+
+print(type(x))
+#
+
+print(x.dtype)
+# [('id', '
+
+print(x.dtype)
+# [('id', ' 1.5 的 iris_data行。**
+
+【知识点:搜索】
+- 如何根据两个或多个条件筛选numpy数组?
+
+
+
+**8. 选择没有任何 nan 值的 iris_data行。**
+
+【知识点:逻辑函数、搜索】
+- 如何从numpy数组中删除包含缺失值的行?
+
+
+
+
+**9. 计算 iris_data 中sepalLength(第1列)和petalLength(第3列)之间的相关系数。**
+
+【知识点:统计相关】
+- 如何计算numpy数组两列之间的相关系数?
+
+
+
+
+
+**10. 找出iris_data是否有任何缺失值。**
+
+【知识点:逻辑函数】
+- 如何查找给定数组是否具有空值?
+
+
+
+
+**11. 在numpy数组中将所有出现的nan替换为0。**
+
+【知识点:逻辑函数】
+- 如何在numpy数组中用0替换所有缺失值?
+
+
+
+**12. 找出鸢尾属植物物种中的唯一值和唯一值出现的数量。**
+
+【知识点:数组操作】
+- 如何在numpy数组中查找唯一值的计数?
+
+
+
+
+**13. 将 iris_data 的花瓣长度(第3列)以形成分类变量的形式显示。定义:Less than 3 --> 'small';3-5 --> 'medium';'>=5 --> 'large'。**
+
+【知识点:统计相关】
+- 如何将数字转换为分类(文本)数组?
+
+
+
+
+
+**14. 在 iris_data 中创建一个新列,其中 volume 是 `(pi x petallength x sepallength ^ 2)/ 3`。**
+
+【知识点:数组操作】
+- 如何从numpy数组的现有列创建新列?
+
+
+
+
+
+**15. 随机抽鸢尾属植物的种类,使得Iris-setosa的数量是Iris-versicolor和Iris-virginica数量的两倍。**
+
+【知识点:随机抽样】
+- 如何在numpy中进行概率抽样?
+
+
+
+
+**16. 根据 sepallength 列对数据集进行排序。**
+
+【知识点:排序】
+- 如何按列对2D数组进行排序?
+
+
+**17. 在鸢尾属植物数据集中找到最常见的花瓣长度值(第3列)。**
+
+【知识点:数组操作】
+- 如何在numpy数组中找出出现次数最多的值?
+
+
+
+
+**18. 在鸢尾花数据集的 petalwidth(第4列)中查找第一次出现的值大于1.0的位置。**
+
+【知识点:搜索】
+- 如何找到第一次出现大于给定值的位置?
\ No newline at end of file
diff --git a/IntroductionToNumpy/dataset/iris.data b/IntroductionToNumpy/dataset/iris.data
new file mode 100644
index 0000000..e20e217
--- /dev/null
+++ b/IntroductionToNumpy/dataset/iris.data
@@ -0,0 +1,152 @@
+sepallength,sepalwidth,petallength,petalwidth,species
+5.1,3.5,1.4,0.2,Iris-setosa
+4.9,3.0,1.4,0.2,Iris-setosa
+4.7,3.2,1.3,0.2,Iris-setosa
+4.6,3.1,1.5,0.2,Iris-setosa
+5.0,3.6,1.4,0.2,Iris-setosa
+5.4,3.9,1.7,0.4,Iris-setosa
+4.6,3.4,1.4,0.3,Iris-setosa
+5.0,3.4,1.5,0.2,Iris-setosa
+4.4,2.9,1.4,0.2,Iris-setosa
+4.9,3.1,1.5,0.1,Iris-setosa
+5.4,3.7,1.5,0.2,Iris-setosa
+4.8,3.4,1.6,0.2,Iris-setosa
+4.8,3.0,1.4,0.1,Iris-setosa
+4.3,3.0,1.1,0.1,Iris-setosa
+5.8,4.0,1.2,0.2,Iris-setosa
+5.7,4.4,1.5,0.4,Iris-setosa
+5.4,3.9,1.3,0.4,Iris-setosa
+5.1,3.5,1.4,0.3,Iris-setosa
+5.7,3.8,1.7,0.3,Iris-setosa
+5.1,3.8,1.5,0.3,Iris-setosa
+5.4,3.4,1.7,0.2,Iris-setosa
+5.1,3.7,1.5,0.4,Iris-setosa
+4.6,3.6,1.0,0.2,Iris-setosa
+5.1,3.3,1.7,0.5,Iris-setosa
+4.8,3.4,1.9,0.2,Iris-setosa
+5.0,3.0,1.6,0.2,Iris-setosa
+5.0,3.4,1.6,0.4,Iris-setosa
+5.2,3.5,1.5,0.2,Iris-setosa
+5.2,3.4,1.4,0.2,Iris-setosa
+4.7,3.2,1.6,0.2,Iris-setosa
+4.8,3.1,1.6,0.2,Iris-setosa
+5.4,3.4,1.5,0.4,Iris-setosa
+5.2,4.1,1.5,0.1,Iris-setosa
+5.5,4.2,1.4,0.2,Iris-setosa
+4.9,3.1,1.5,0.1,Iris-setosa
+5.0,3.2,1.2,0.2,Iris-setosa
+5.5,3.5,1.3,0.2,Iris-setosa
+4.9,3.1,1.5,0.1,Iris-setosa
+4.4,3.0,1.3,0.2,Iris-setosa
+5.1,3.4,1.5,0.2,Iris-setosa
+5.0,3.5,1.3,0.3,Iris-setosa
+4.5,2.3,1.3,0.3,Iris-setosa
+4.4,3.2,1.3,0.2,Iris-setosa
+5.0,3.5,1.6,0.6,Iris-setosa
+5.1,3.8,1.9,0.4,Iris-setosa
+4.8,3.0,1.4,0.3,Iris-setosa
+5.1,3.8,1.6,0.2,Iris-setosa
+4.6,3.2,1.4,0.2,Iris-setosa
+5.3,3.7,1.5,0.2,Iris-setosa
+5.0,3.3,1.4,0.2,Iris-setosa
+7.0,3.2,4.7,1.4,Iris-versicolor
+6.4,3.2,4.5,1.5,Iris-versicolor
+6.9,3.1,4.9,1.5,Iris-versicolor
+5.5,2.3,4.0,1.3,Iris-versicolor
+6.5,2.8,4.6,1.5,Iris-versicolor
+5.7,2.8,4.5,1.3,Iris-versicolor
+6.3,3.3,4.7,1.6,Iris-versicolor
+4.9,2.4,3.3,1.0,Iris-versicolor
+6.6,2.9,4.6,1.3,Iris-versicolor
+5.2,2.7,3.9,1.4,Iris-versicolor
+5.0,2.0,3.5,1.0,Iris-versicolor
+5.9,3.0,4.2,1.5,Iris-versicolor
+6.0,2.2,4.0,1.0,Iris-versicolor
+6.1,2.9,4.7,1.4,Iris-versicolor
+5.6,2.9,3.6,1.3,Iris-versicolor
+6.7,3.1,4.4,1.4,Iris-versicolor
+5.6,3.0,4.5,1.5,Iris-versicolor
+5.8,2.7,4.1,1.0,Iris-versicolor
+6.2,2.2,4.5,1.5,Iris-versicolor
+5.6,2.5,3.9,1.1,Iris-versicolor
+5.9,3.2,4.8,1.8,Iris-versicolor
+6.1,2.8,4.0,1.3,Iris-versicolor
+6.3,2.5,4.9,1.5,Iris-versicolor
+6.1,2.8,4.7,1.2,Iris-versicolor
+6.4,2.9,4.3,1.3,Iris-versicolor
+6.6,3.0,4.4,1.4,Iris-versicolor
+6.8,2.8,4.8,1.4,Iris-versicolor
+6.7,3.0,5.0,1.7,Iris-versicolor
+6.0,2.9,4.5,1.5,Iris-versicolor
+5.7,2.6,3.5,1.0,Iris-versicolor
+5.5,2.4,3.8,1.1,Iris-versicolor
+5.5,2.4,3.7,1.0,Iris-versicolor
+5.8,2.7,3.9,1.2,Iris-versicolor
+6.0,2.7,5.1,1.6,Iris-versicolor
+5.4,3.0,4.5,1.5,Iris-versicolor
+6.0,3.4,4.5,1.6,Iris-versicolor
+6.7,3.1,4.7,1.5,Iris-versicolor
+6.3,2.3,4.4,1.3,Iris-versicolor
+5.6,3.0,4.1,1.3,Iris-versicolor
+5.5,2.5,4.0,1.3,Iris-versicolor
+5.5,2.6,4.4,1.2,Iris-versicolor
+6.1,3.0,4.6,1.4,Iris-versicolor
+5.8,2.6,4.0,1.2,Iris-versicolor
+5.0,2.3,3.3,1.0,Iris-versicolor
+5.6,2.7,4.2,1.3,Iris-versicolor
+5.7,3.0,4.2,1.2,Iris-versicolor
+5.7,2.9,4.2,1.3,Iris-versicolor
+6.2,2.9,4.3,1.3,Iris-versicolor
+5.1,2.5,3.0,1.1,Iris-versicolor
+5.7,2.8,4.1,1.3,Iris-versicolor
+6.3,3.3,6.0,2.5,Iris-virginica
+5.8,2.7,5.1,1.9,Iris-virginica
+7.1,3.0,5.9,2.1,Iris-virginica
+6.3,2.9,5.6,1.8,Iris-virginica
+6.5,3.0,5.8,2.2,Iris-virginica
+7.6,3.0,6.6,2.1,Iris-virginica
+4.9,2.5,4.5,1.7,Iris-virginica
+7.3,2.9,6.3,1.8,Iris-virginica
+6.7,2.5,5.8,1.8,Iris-virginica
+7.2,3.6,6.1,2.5,Iris-virginica
+6.5,3.2,5.1,2.0,Iris-virginica
+6.4,2.7,5.3,1.9,Iris-virginica
+6.8,3.0,5.5,2.1,Iris-virginica
+5.7,2.5,5.0,2.0,Iris-virginica
+5.8,2.8,5.1,2.4,Iris-virginica
+6.4,3.2,5.3,2.3,Iris-virginica
+6.5,3.0,5.5,1.8,Iris-virginica
+7.7,3.8,6.7,2.2,Iris-virginica
+7.7,2.6,6.9,2.3,Iris-virginica
+6.0,2.2,5.0,1.5,Iris-virginica
+6.9,3.2,5.7,2.3,Iris-virginica
+5.6,2.8,4.9,2.0,Iris-virginica
+7.7,2.8,6.7,2.0,Iris-virginica
+6.3,2.7,4.9,1.8,Iris-virginica
+6.7,3.3,5.7,2.1,Iris-virginica
+7.2,3.2,6.0,1.8,Iris-virginica
+6.2,2.8,4.8,1.8,Iris-virginica
+6.1,3.0,4.9,1.8,Iris-virginica
+6.4,2.8,5.6,2.1,Iris-virginica
+7.2,3.0,5.8,1.6,Iris-virginica
+7.4,2.8,6.1,1.9,Iris-virginica
+7.9,3.8,6.4,2.0,Iris-virginica
+6.4,2.8,5.6,2.2,Iris-virginica
+6.3,2.8,5.1,1.5,Iris-virginica
+6.1,2.6,5.6,1.4,Iris-virginica
+7.7,3.0,6.1,2.3,Iris-virginica
+6.3,3.4,5.6,2.4,Iris-virginica
+6.4,3.1,5.5,1.8,Iris-virginica
+6.0,3.0,4.8,1.8,Iris-virginica
+6.9,3.1,5.4,2.1,Iris-virginica
+6.7,3.1,5.6,2.4,Iris-virginica
+6.9,3.1,5.1,2.3,Iris-virginica
+5.8,2.7,5.1,1.9,Iris-virginica
+6.8,3.2,5.9,2.3,Iris-virginica
+6.7,3.3,5.7,2.5,Iris-virginica
+6.7,3.0,5.2,2.3,Iris-virginica
+6.3,2.5,5.0,1.9,Iris-virginica
+6.5,3.0,5.2,2.0,Iris-virginica
+6.2,3.4,5.4,2.3,Iris-virginica
+5.9,3.0,5.1,1.8,Iris-virginica
+
diff --git a/IntroductionToNumpy/readme.md b/IntroductionToNumpy/readme.md
index 4b21674..f4c7b3c 100644
--- a/IntroductionToNumpy/readme.md
+++ b/IntroductionToNumpy/readme.md
@@ -50,7 +50,7 @@
## 基本信息
-- 学习周期:11天,每天平均花费时间3小时-5小时不等,根据个人学习接受能力强弱有所浮动。
+- 学习周期:10天,每天平均花费时间3小时-5小时不等,根据个人学习接受能力强弱有所浮动。
- 学习形式:理论学习 + 练习
- 人群定位:有一定python编程的基础。
- 先修内容:[Python编程语言](https://github.com/datawhalechina/team-learning-program/tree/master/PythonLanguage)
@@ -71,7 +71,7 @@
- 熟悉打开规则
-### Task01:输入输出(2天)
+### Task01:输入输出(1天)
- 熟悉 Numpy 如何处理二进制文件和文本文件。
diff --git a/IntroductionToNumpy/task06 输入输出/14. 输入和输出-练习题.ipynb b/IntroductionToNumpy/task06 输入输出/14. 输入和输出-练习题.ipynb
deleted file mode 100644
index 104b206..0000000
--- a/IntroductionToNumpy/task06 输入输出/14. 输入和输出-练习题.ipynb
+++ /dev/null
@@ -1,229 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2020-09-06T03:05:42.613206Z",
- "start_time": "2020-09-06T03:05:42.609217Z"
- }
- },
- "source": [
- "**只打印或显示numpy数组rand_arr的小数点后3位。**\n",
- "\n",
- "- `rand_arr = np.random.random([5, 3])`\n",
- "\n",
- "【知识点:输入和输出】\n",
- "- 如何在numpy数组中只打印小数点后三位?"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "ExecuteTime": {
- "end_time": "2020-09-06T03:06:03.840763Z",
- "start_time": "2020-09-06T03:06:03.834778Z"
- }
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[[0.25106063 0.32735642 0.17623774]\n",
- " [0.85566173 0.11420437 0.53735783]\n",
- " [0.82253612 0.07625331 0.9358199 ]\n",
- " [0.97268875 0.91794448 0.61845404]\n",
- " [0.58615827 0.28096349 0.88048956]]\n",
- "[[0.251 0.327 0.176]\n",
- " [0.856 0.114 0.537]\n",
- " [0.823 0.076 0.936]\n",
- " [0.973 0.918 0.618]\n",
- " [0.586 0.281 0.88 ]]\n"
- ]
- }
- ],
- "source": [
- "import numpy as np\n",
- "\n",
- "rand_arr = np.random.random([5, 3])\n",
- "print(rand_arr)\n",
- "# [[0.33033427 0.05538836 0.05947305]\n",
- "# [0.36199439 0.48844555 0.26309599]\n",
- "# [0.05361816 0.71539075 0.60645637]\n",
- "# [0.95000384 0.31424729 0.41032467]\n",
- "# [0.36082793 0.50101268 0.6306832 ]]\n",
- "\n",
- "np.set_printoptions(precision=3)\n",
- "print(rand_arr)\n",
- "# [[0.33 0.055 0.059]\n",
- "# [0.362 0.488 0.263]\n",
- "# [0.054 0.715 0.606]\n",
- "# [0.95 0.314 0.41 ]\n",
- "# [0.361 0.501 0.631]]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2020-09-06T03:06:22.855956Z",
- "start_time": "2020-09-06T03:06:22.850970Z"
- }
- },
- "source": [
- "**将numpy数组a中打印的项数限制为最多6个元素。**\n",
- "\n",
- "【知识点:输入和输出】\n",
- "- 如何限制numpy数组输出中打印的项目数?"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "ExecuteTime": {
- "end_time": "2020-09-06T03:06:51.128200Z",
- "start_time": "2020-09-06T03:06:51.123215Z"
- }
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]\n",
- "[ 0 1 2 ... 12 13 14]\n"
- ]
- }
- ],
- "source": [
- "import numpy as np\n",
- "\n",
- "a = np.arange(15)\n",
- "print(a)\n",
- "# [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]\n",
- "np.set_printoptions(threshold=6)\n",
- "print(a)\n",
- "# [ 0 1 2 ... 12 13 14]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2020-09-06T03:07:14.131621Z",
- "start_time": "2020-09-06T03:07:14.126608Z"
- }
- },
- "source": [
- "**打印完整的numpy数组a而不中断。**\n",
- "\n",
- "【知识点:输入和输出】\n",
- "- 如何打印完整的numpy数组而不中断?"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "ExecuteTime": {
- "end_time": "2020-09-06T03:07:47.868079Z",
- "start_time": "2020-09-06T03:07:47.863126Z"
- }
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[ 0 1 2 ... 12 13 14]\n",
- "[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]\n"
- ]
- }
- ],
- "source": [
- "import numpy as np\n",
- "\n",
- "a = np.arange(15)\n",
- "np.set_printoptions(threshold=6)\n",
- "print(a)\n",
- "# [ 0 1 2 ... 12 13 14]\n",
- "np.set_printoptions(threshold=np.iinfo(np.int).max)\n",
- "print(a)\n",
- "# [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python35",
- "language": "python",
- "name": "python35"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.10"
- },
- "toc": {
- "base_numbering": 1,
- "nav_menu": {},
- "number_sections": true,
- "sideBar": true,
- "skip_h1_title": false,
- "title_cell": "Table of Contents",
- "title_sidebar": "Contents",
- "toc_cell": false,
- "toc_position": {},
- "toc_section_display": true,
- "toc_window_display": false
- },
- "varInspector": {
- "cols": {
- "lenName": 16,
- "lenType": 16,
- "lenVar": 40
- },
- "kernels_config": {
- "python": {
- "delete_cmd_postfix": "",
- "delete_cmd_prefix": "del ",
- "library": "var_list.py",
- "varRefreshCmd": "print(var_dic_list())"
- },
- "r": {
- "delete_cmd_postfix": ") ",
- "delete_cmd_prefix": "rm(",
- "library": "var_list.r",
- "varRefreshCmd": "cat(var_dic_list()) "
- }
- },
- "types_to_exclude": [
- "module",
- "function",
- "builtin_function_or_method",
- "instance",
- "_Feature"
- ],
- "window_display": false
- }
- },
- "nbformat": 4,
- "nbformat_minor": 4
-}
diff --git a/IntroductionToNumpy/task06 输入输出/14. 输入和输出.ipynb b/IntroductionToNumpy/task06 输入输出/14. 输入和输出.ipynb
deleted file mode 100644
index 154c3a9..0000000
--- a/IntroductionToNumpy/task06 输入输出/14. 输入和输出.ipynb
+++ /dev/null
@@ -1,372 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# 输入和输出\n",
- "\n",
- "\n",
- "\n",
- "## numpy 二进制文件\n",
- "\n",
- "`save()`、`savez()`和`load()`函数以 numpy 专用的二进制类型(npy、npz)保存和读取数据,这三个函数会自动处理ndim、dtype、shape等信息,使用它们读写数组非常方便,但是`save()`输出的文件很难与其它语言编写的程序兼容。\n",
- "\n",
- "npy格式:以二进制的方式存储文件,在二进制文件第一行以文本形式保存了数据的元信息(ndim,dtype,shape等),可以用二进制工具查看内容。\n",
- "\n",
- "npz格式:以压缩打包的方式存储文件,可以用压缩软件解压。\n",
- "\n",
- "\n",
- "- `numpy.save(file, arr, allow_pickle=True, fix_imports=True)` Save an array to a binary file in NumPy `.npy` format.\n",
- "- `numpy.load(file, mmap_mode=None, allow_pickle=False, fix_imports=True, encoding='ASCII')` Load arrays or pickled objects from ``.npy``, ``.npz`` or pickled files.\n",
- "\n",
- "\n",
- "【例】\n",
- "```python\n",
- "import numpy as np\n",
- "\n",
- "outfile = r'.\\test.npy'\n",
- "np.random.seed(20200619)\n",
- "x = np.random.uniform(0, 1, [3, 5])\n",
- "np.save(outfile, x)\n",
- "y = np.load(outfile)\n",
- "print(y)\n",
- "# [[0.01123594 0.66790705 0.50212171 0.7230908 0.61668256]\n",
- "# [0.00668332 0.1234096 0.96092409 0.67925305 0.38596837]\n",
- "# [0.72342998 0.26258324 0.24318845 0.98795012 0.77370715]]\n",
- "```\n",
- "\n",
- "- `numpy.savez(file, *args, **kwds)` Save several arrays into a single file in uncompressed `.npz` format.\n",
- "\n",
- "`savez()`第一个参数是文件名,其后的参数都是需要保存的数组,也可以使用关键字参数为数组起一个名字,非关键字参数传递的数组会自动起名为`arr_0, arr_1, …`。\n",
- "\n",
- "`savez()`输出的是一个压缩文件(扩展名为npz),其中每个文件都是一个`save()`保存的npy文件,文件名对应于数组名。`load()`自动识别npz文件,并且返回一个类似于字典的对象,可以通过数组名作为关键字获取数组的内容。\n",
- "\n",
- "【例】将多个数组保存到一个文件,可以使用`numpy.savez()`函数。\n",
- "```python\n",
- "import numpy as np\n",
- "\n",
- "outfile = r'.\\test.npz'\n",
- "x = np.linspace(0, np.pi, 5)\n",
- "y = np.sin(x)\n",
- "z = np.cos(x)\n",
- "np.savez(outfile, x, y, z_d=z)\n",
- "data = np.load(outfile)\n",
- "np.set_printoptions(suppress=True)\n",
- "print(data.files) \n",
- "# ['z_d', 'arr_0', 'arr_1']\n",
- "\n",
- "print(data['arr_0'])\n",
- "# [0. 0.78539816 1.57079633 2.35619449 3.14159265]\n",
- "\n",
- "print(data['arr_1'])\n",
- "# [0. 0.70710678 1. 0.70710678 0. ]\n",
- "\n",
- "print(data['z_d'])\n",
- "# [ 1. 0.70710678 0. -0.70710678 -1. ]\n",
- "```\n",
- "\n",
- "用解压软件打开 test.npz 文件,会发现其中有三个文件:`arr_0.npy,arr_1.npy,z_d.npy`,其中分别保存着数组`x,y,z`的内容。\n",
- "\n",
- "\n",
- "---\n",
- "## 文本文件\n",
- "`savetxt()`,`loadtxt()`和`genfromtxt()`函数用来存储和读取文本文件(如TXT,CSV等)。`genfromtxt()`比`loadtxt()`更加强大,可对缺失数据进行处理。\n",
- "\n",
- "- `numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\\n', header='', footer='', comments='# ', encoding=None)` Save an array to a text file.\n",
- " - fname:文件路径\n",
- " - X:存入文件的数组。\n",
- " - fmt:写入文件中每个元素的字符串格式,默认'%.18e'(保留18位小数的浮点数形式)。\n",
- " - delimiter:分割字符串,默认以空格分隔。\n",
- "\n",
- "\n",
- "- `numpy.loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0, encoding='bytes', max_rows=None)` Load data from a text file. \n",
- " - fname:文件路径。\n",
- " - dtype:数据类型,默认为float。\n",
- " - comments: 字符串或字符串组成的列表,默认为# , 表示注释字符集开始的标志。\n",
- " - skiprows:跳过多少行,一般跳过第一行表头。\n",
- " - usecols:元组(元组内数据为列的数值索引), 用来指定要读取数据的列(第一列为0)。\n",
- " - unpack:当加载多列数据时是否需要将数据列进行解耦赋值给不同的变量。\n",
- "\n",
- "\n",
- "\n",
- "\n",
- "\n",
- "【例】写入和读出TXT文件。\n",
- "```python\n",
- "import numpy as np\n",
- "\n",
- "outfile = r'.\\test.txt'\n",
- "x = np.arange(0, 10).reshape(2, -1)\n",
- "np.savetxt(outfile, x)\n",
- "y = np.loadtxt(outfile)\n",
- "print(y)\n",
- "# [[0. 1. 2. 3. 4.]\n",
- "# [5. 6. 7. 8. 9.]]\n",
- "```\n",
- "\n",
- "test.txt文件如下:\n",
- "\n",
- "```python\n",
- "0.000000000000000000e+00 1.000000000000000000e+00 2.000000000000000000e+00 3.000000000000000000e+00 4.000000000000000000e+00\n",
- "5.000000000000000000e+00 6.000000000000000000e+00 7.000000000000000000e+00 8.000000000000000000e+00 9.000000000000000000e+00\n",
- "```\n",
- "\n",
- "\n",
- "【例】写入和读出CSV文件。\n",
- "```python\n",
- "import numpy as np\n",
- "\n",
- "outfile = r'.\\test.csv'\n",
- "x = np.arange(0, 10, 0.5).reshape(4, -1)\n",
- "np.savetxt(outfile, x, fmt='%.3f', delimiter=',')\n",
- "y = np.loadtxt(outfile, delimiter=',')\n",
- "print(y)\n",
- "# [[0. 0.5 1. 1.5 2. ]\n",
- "# [2.5 3. 3.5 4. 4.5]\n",
- "# [5. 5.5 6. 6.5 7. ]\n",
- "# [7.5 8. 8.5 9. 9.5]]\n",
- "```\n",
- "\n",
- "test.csv文件如下:\n",
- "```python\n",
- "0.000,0.500,1.000,1.500,2.000\n",
- "2.500,3.000,3.500,4.000,4.500\n",
- "5.000,5.500,6.000,6.500,7.000\n",
- "7.500,8.000,8.500,9.000,9.500\n",
- "```\n",
- "\n",
- "\n",
- "\n",
- "`genfromtxt()`是面向结构数组和缺失数据处理的。\n",
- "\n",
- "- `numpy.genfromtxt(fname, dtype=float, comments='#', delimiter=None, skip_header=0, skip_footer=0, converters=None, missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletechars=''.join(sorted(NameValidator.defaultdeletechars)), replace_space='_', autostrip=False, case_sensitive=True, defaultfmt=\"f%i\", unpack=None, usemask=False, loose=True, invalid_raise=True, max_rows=None, encoding='bytes')` Load data from a text file, with missing values handled as specified.\n",
- " - names:设置为True时,程序将把第一行作为列名称。\n",
- "\n",
- "\n",
- "data.csv文件如下:\n",
- "```python\n",
- "id,value1,value2,value3\n",
- "1,123,1.4,23\n",
- "2,110,0.5,18\n",
- "3,164,2.1,19\n",
- "```\n",
- "\n",
- "【例】\n",
- "```python\n",
- "import numpy as np\n",
- "\n",
- "outfile = r'.\\data.csv'\n",
- "x = np.loadtxt(outfile, delimiter=',', skiprows=1)\n",
- "print(x)\n",
- "# [[ 1. 123. 1.4 23. ]\n",
- "# [ 2. 110. 0.5 18. ]\n",
- "# [ 3. 164. 2.1 19. ]]\n",
- "\n",
- "x = np.loadtxt(outfile, delimiter=',', skiprows=1, usecols=(1, 2))\n",
- "print(x)\n",
- "# [[123. 1.4]\n",
- "# [110. 0.5]\n",
- "# [164. 2.1]]\n",
- "\n",
- "val1, val2 = np.loadtxt(outfile, delimiter=',', skiprows=1, usecols=(1, 2), unpack=True)\n",
- "print(val1) # [123. 110. 164.]\n",
- "print(val2) # [1.4 0.5 2.1]\n",
- "```\n",
- "\n",
- "\n",
- "【例】\n",
- "```python\n",
- "import numpy as np\n",
- "\n",
- "outfile = r'.\\data.csv'\n",
- "x = np.genfromtxt(outfile, delimiter=',', names=True)\n",
- "print(x)\n",
- "# [(1., 123., 1.4, 23.) (2., 110., 0.5, 18.) (3., 164., 2.1, 19.)]\n",
- "\n",
- "print(type(x)) \n",
- "# \n",
- "\n",
- "print(x.dtype)\n",
- "# [('id', '\n",
- "\n",
- "print(x.dtype)\n",
- "# [('id', '微信公众号:LSGO软件技术团队|华北电力大学
+韩绘锦|CSDN:https://blog.csdn.net/weixin_45569785|华北电力大学
+姚行志|CSDN:https://blog.csdn.net/soulmate______|华北电力大学
+徐韬||华北电力大学
+
+
+
+
+
diff --git a/Turtle/readme.md b/Turtle/readme.md
new file mode 100644
index 0000000..72f7278
--- /dev/null
+++ b/Turtle/readme.md
@@ -0,0 +1,2 @@
+## 简介
+
diff --git a/ValentineDay/readme.md b/ValentineDay/readme.md
new file mode 100644
index 0000000..72f7278
--- /dev/null
+++ b/ValentineDay/readme.md
@@ -0,0 +1,2 @@
+## 简介
+
diff --git a/readme.md b/readme.md
index f1dfeba..ad3eb96 100644
--- a/readme.md
+++ b/readme.md
@@ -13,6 +13,9 @@
- [编程实践(Python 爬虫)](https://github.com/datawhalechina/team-learning-program/tree/master/WebSpider)
- [编程实践(Python综合)](https://github.com/datawhalechina/team-learning-program/tree/master/ProjectPractice)
- [编程实践(设计模式)](https://github.com/datawhalechina/team-learning-program/tree/master/DesignPattern)
+- [编程实践(欢欢喜喜情人节)](https://github.com/datawhalechina/team-learning-program/tree/master/ValentineDay)
+- [编程实践(青少年编程Turtle)](https://github.com/datawhalechina/team-learning-program/tree/master/Turtle)
+
## 备注