From aa1d68e40cbb963bf45ce90ff63338bfc2ce0569 Mon Sep 17 00:00:00 2001 From: Tonshel <190323808@qq.com> Date: Sun, 8 Nov 2020 17:39:00 +0800 Subject: [PATCH 1/6] =?UTF-8?q?week1,=20=E7=A7=BB=E5=8A=A80=E5=8F=8C?= =?UTF-8?q?=E6=8C=87=E9=92=88,=E4=BD=9C=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Week_01/\347\247\273\345\212\2500.py" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "Week_01/\347\247\273\345\212\2500.py" diff --git "a/Week_01/\347\247\273\345\212\2500.py" "b/Week_01/\347\247\273\345\212\2500.py" new file mode 100644 index 00000000..e69de29b From 0d1aab3aaacfed91fb8d20d7dfe430559044b89d Mon Sep 17 00:00:00 2001 From: Tonshel <190323808@qq.com> Date: Sun, 8 Nov 2020 18:10:02 +0800 Subject: [PATCH 2/6] =?UTF-8?q?delete=20=E7=A7=BB=E5=8A=A80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Week_01/\347\247\273\345\212\2500.py" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "Week_01/\347\247\273\345\212\2500.py" diff --git "a/Week_01/\347\247\273\345\212\2500.py" "b/Week_01/\347\247\273\345\212\2500.py" deleted file mode 100644 index e69de29b..00000000 From 110709d26c0d0f3845879667f1979e05262edf69 Mon Sep 17 00:00:00 2001 From: Tonshel <190323808@qq.com> Date: Sun, 8 Nov 2020 18:12:29 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A2=98=E7=9B=AE=20?= =?UTF-8?q?=E7=A7=BB=E5=8A=A80=20=E7=9A=84=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Week_01/\347\247\273\345\212\2500/main.py" | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "Week_01/\347\247\273\345\212\2500/main.py" diff --git "a/Week_01/\347\247\273\345\212\2500/main.py" "b/Week_01/\347\247\273\345\212\2500/main.py" new file mode 100644 index 00000000..cf4a5e66 --- /dev/null +++ "b/Week_01/\347\247\273\345\212\2500/main.py" @@ -0,0 +1,25 @@ +# This is a sample Python script. + +# Press ⌃R to execute it or replace it with your code. +# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings. + + +def moveZore(nums): + j = 0 + for i in range(len(nums)): + if nums[i] != 0: + nums[j] = nums[i] + j += 1 + for i in range(j,len(nums)): + nums[i] = 0 + print(nums) + + + + + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + #print_hi('PyCharm') + moveZore([0,1,0,3,4,5]) +# See PyCharm help at https://www.jetbrains.com/help/pycharm/ From ddfe65e5d17e8e85ef1bf77dbfb324a7a404a098 Mon Sep 17 00:00:00 2001 From: Tonshel <190323808@qq.com> Date: Sun, 8 Nov 2020 19:01:31 +0800 Subject: [PATCH 4/6] =?UTF-8?q?readMe=20=E7=AC=AC=E4=B8=80=E5=91=A8?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E6=80=BB=E7=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week_01/README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/Week_01/README.md b/Week_01/README.md index 50de3041..4da82572 100644 --- a/Week_01/README.md +++ b/Week_01/README.md @@ -1 +1,57 @@ -学习笔记 \ No newline at end of file +# 第一周总结 + +[TOC] + +## 一、时间复杂度 + +方法:根据N的执行的次数判断 + +1. O(1) 常数复杂度 +2. O(n) 线性的时间复杂度 (n是多少就执行多少次) +3. 1. 嵌套的时间复杂度是指数的 两层的话是 O(n2) + 2. 三层的话是 O(n3) ,以此类推 +4. 二分查找的 O(logn) +5. 二叉树的遍历 o(n) 前 中 后的遍历 +6. 图的遍历 也是 o(n) +7. 数组的长度就是数组的空间复杂度 + +*下意识的分析时间复杂度的用处,N越大,越是有天壤之别* + + + +## 二、双指针 + +1. 快慢指针:例如移动0,快指针是最外层遍历的i,慢指针作用于对非零元素的累加。这样有小解决了,非零元素的移动(慢),以及元素可能处理有遗漏的为问题(快) + +2. 左右夹逼:在题目“盛最多的水的容器”中,通过左右指针去处理两个元素之间的距离,以及元素的最小值,最后通过刷新max,求解。左右指针的移动最关键的是,什么样的条件触发移动,以及该谁动,动多远。这个关键点在题目“三数之和”中充分体现。 + + > “三数之和”中对数组排序的原因, + > + > ​ 1.在不排序的情况下, 跑完程序会漏掉一些答案 + > + > ​ 2.排序后对于判断target是否大于0,有着关键作用,而且这个判断,对时间复杂度的影响显著 + > + > ​ 3.对于指针的移动也有关系,如果结果大于0,那么有指针左移动,即,想小的趋势的方向移动,反之,左指针移动,向大的趋势的方向移动。而“盛最多的水的容器”中的移动是谁小谁动,因为要找到最大的面积。 + + + +## 三、栈的思想在业务代码中的实践 + + 1. 自顶向下的写功能,先写主干,在写主干内部的分支。这样能让条理清晰,看问题是从整体到局部。 + 2. 栈的思想运用:使用pop对栈顶元素处理。 + +## 四、学习方法 + + 1. 双指针类的题目的思维方式是升维。 + 2. 题目“上台阶”的是找到可重复的子问题。再往if else ,for while,递归上靠。 + + + + + + + + + + + From 900363b1527eb1aa12196e45f50ef3045bf03921 Mon Sep 17 00:00:00 2001 From: Tonshel <190323808@qq.com> Date: Sun, 8 Nov 2020 22:56:29 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=B8=A4=E6=9D=9F=E4=B9=8B=E5=92=8C?= =?UTF-8?q?=E9=A2=98=E8=A7=A3=EF=BC=8C=E6=9A=B4=E5=8A=9B+=E5=93=88?= =?UTF-8?q?=E5=B8=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main.py" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "Week_01/\344\270\244\346\225\260\344\271\213\345\222\214/main.py" diff --git "a/Week_01/\344\270\244\346\225\260\344\271\213\345\222\214/main.py" "b/Week_01/\344\270\244\346\225\260\344\271\213\345\222\214/main.py" new file mode 100644 index 00000000..4530433e --- /dev/null +++ "b/Week_01/\344\270\244\346\225\260\344\271\213\345\222\214/main.py" @@ -0,0 +1,32 @@ +# This is a sample Python script. + +# Press ⌃R to execute it or replace it with your code. +# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings. + + + +#两数之和 暴力法 (时间复杂度高,O(n^2)) +def twoSum(nums,target): + sumsArray = [] + for i in range(len(nums)): + for j in range(i+1,len(nums)): + if target - nums[j] == nums[i] : + array = [i,j] + sumsArray.append(array); + continue; + print(sumsArray) + +# 哈希解法 +def twoSum_Hash(nums,target): + hashTable = {} + for i,num in enumerate(nums): + if target - num in hashTable : + return [hashTable[target - num],i] + hashTable[nums[i]] = i + + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + #twoSum([2, 7, 11, 15],9) + print(twoSum_Hash([2, 7, 11, 15],9)) +# See PyCharm help at https://www.jetbrains.com/help/pycharm/ From b8bbdfbf069950852b50e8c4fb11df3fbda47d68 Mon Sep 17 00:00:00 2001 From: Tonshel <190323808@qq.com> Date: Sun, 15 Nov 2020 23:55:56 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E5=91=A8=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week_02/README.md | 56 ++++++++++++++++++- .../main.py" | 32 +++++++++++ .../main.py" | 32 +++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 "Week_02/\344\270\244\346\225\260\344\271\213\345\222\214/main.py" create mode 100644 "Week_02/\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/main.py" diff --git a/Week_02/README.md b/Week_02/README.md index 50de3041..e3326a0f 100644 --- a/Week_02/README.md +++ b/Week_02/README.md @@ -1 +1,55 @@ -学习笔记 \ No newline at end of file +# 第二周总结 + +### 一、堆 + +1、Heap 是一种数据结构,用于在一组数中,迅速的找到最大值和最小值。 + +时间复杂度,取决于,堆的层级。find-max 是o(1)/ find-min 也是 o(1) + +2、 具体的堆,包括二叉堆,和斐波那契堆等, + +按照根节点,划分有大顶堆和小顶堆。 + +3、二叉堆 + +性质1,完全的二叉树,以保证查找索引方便, + +性质2, 父节点大于等于子节点。一次来保证,根节点是最大的。 + + (1)插入操作 + +​ headUp,新元素放到按照顺序放到叶子节点,然后与父节点,相比较,如果大于父节点,就交换,依次向上浮动,直到小于他的父节点。 + +​ (2)删除操作 + +​ 删除一个元素,然后将叶子节点跟该节点交换,再用该节点与最大的子节点相比较,如果小于最大的子节点,就交换位置。 + + + + + +### 二、二叉搜索树 + +树是链表的升维的思想 + +数组的遍历,是循序的,二叉树的遍历是分左、有字数的 + +1、前序: 根-左-右 + +2、中序:左-根-右 + +3、后序:左-右-根 + +二叉搜索树的数据结构,本身就是左子树的所有节点,小于右子数的所有节点。 + +(1) 查找 + +这样在查找的时候,就类似二分查找,一次就能过滤掉一半。时间复杂度是 o(logn) + +(2)插入 + +也是按照二分法插入,知道这个位置没有其他节点,表示,这个位置属于待插入的节点.创建二叉搜索树,也就是在一个空数中调用插入操作。 + +(3)删除 + +一个节点后,去找他的右子树的最小节点,或者左子树的最大节点 \ No newline at end of file diff --git "a/Week_02/\344\270\244\346\225\260\344\271\213\345\222\214/main.py" "b/Week_02/\344\270\244\346\225\260\344\271\213\345\222\214/main.py" new file mode 100644 index 00000000..4530433e --- /dev/null +++ "b/Week_02/\344\270\244\346\225\260\344\271\213\345\222\214/main.py" @@ -0,0 +1,32 @@ +# This is a sample Python script. + +# Press ⌃R to execute it or replace it with your code. +# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings. + + + +#两数之和 暴力法 (时间复杂度高,O(n^2)) +def twoSum(nums,target): + sumsArray = [] + for i in range(len(nums)): + for j in range(i+1,len(nums)): + if target - nums[j] == nums[i] : + array = [i,j] + sumsArray.append(array); + continue; + print(sumsArray) + +# 哈希解法 +def twoSum_Hash(nums,target): + hashTable = {} + for i,num in enumerate(nums): + if target - num in hashTable : + return [hashTable[target - num],i] + hashTable[nums[i]] = i + + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + #twoSum([2, 7, 11, 15],9) + print(twoSum_Hash([2, 7, 11, 15],9)) +# See PyCharm help at https://www.jetbrains.com/help/pycharm/ diff --git "a/Week_02/\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/main.py" "b/Week_02/\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/main.py" new file mode 100644 index 00000000..d5eb859d --- /dev/null +++ "b/Week_02/\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215/main.py" @@ -0,0 +1,32 @@ +# This is a sample Python script. + +# Press ⌃R to execute it or replace it with your code. +# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings. + + +def print_hi(name): + # Use a breakpoint in the code line below to debug your script. + print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint. +# 有效的字幕异位词 +def isAnagram(s:str,t:str) -> bool: + if len(s) != len(t): + return False + array = [] + for i in range(26): + array.append(0) + + for i in range(len(s)): + array[ord(s[i]) - ord('a')] += 1 + array[ord(t[i]) - ord('a')] -= 1 + for i in array: + if i != 0: + return False + return True + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + print_hi('PyCharm') + isSuccess = isAnagram(s="abc", t="bac") + print(isSuccess) + +# See PyCharm help at https://www.jetbrains.com/help/pycharm/