From 2d28ac483a53825b564e9c319cef4ada821a0177 Mon Sep 17 00:00:00 2001 From: greyireland Date: Fri, 19 Jun 2020 18:34:03 +0800 Subject: [PATCH 01/15] update readme --- README.md | 28 ++++++++++++++-------------- TODO.md | 8 ++++++++ practice_algorithm/bplus.md | 1 + practice_algorithm/data_index.md | 1 + practice_algorithm/skiplist.md | 1 + 5 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 TODO.md create mode 100644 practice_algorithm/bplus.md create mode 100644 practice_algorithm/data_index.md create mode 100644 practice_algorithm/skiplist.md diff --git a/README.md b/README.md index 6a360f27..b00ec9c4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![来刷题了](https://img.fuiboom.com/img/title.png) -算法模板,最科学的刷题方式,最快速的刷题路径,一个月从入门到 offer,你值得拥有~ +算法模板,最科学的刷题方式,最快速的刷题路径,一个月从入门到 offer,你值得拥有 🐶~ 算法模板顾名思义就是刷题的套路模板,掌握了刷题模板之后,刷题也变得好玩起来了~ @@ -16,28 +16,28 @@ ### 入门篇 🐶 -- [go 语言入门](introduction/golang.md) -- [算法快速入门](introduction/quickstart.md) +- [go 语言入门](https://github.com/greyireland/algorithm-pattern/blob/master/introduction/golang.md) +- [算法快速入门](https://github.com/greyireland/algorithm-pattern/blob/master/introduction/quickstart.md) ### 数据结构篇 🐰 -- [二叉树](data_structure/binary_tree.md) -- [链表](data_structure/linked_list.md) -- [栈和队列](data_structure/stack_queue.md) -- [二进制](data_structure/binary_op.md) +- [二叉树](https://github.com/greyireland/algorithm-pattern/blob/master/data_structure/binary_tree.md) +- [链表](https://github.com/greyireland/algorithm-pattern/blob/master/data_structure/linked_list.md) +- [栈和队列](https://github.com/greyireland/algorithm-pattern/blob/master/data_structure/stack_queue.md) +- [二进制](https://github.com/greyireland/algorithm-pattern/blob/master/data_structure/binary_op.md) ### 基础算法篇 🐮 -- [二分搜索](basic_algorithm/binary_search.md) -- [排序算法](basic_algorithm/sort.md) -- [动态规划](basic_algorithm/dp.md) +- [二分搜索](https://github.com/greyireland/algorithm-pattern/blob/master/basic_algorithm/binary_search.md) +- [排序算法](https://github.com/greyireland/algorithm-pattern/blob/master/basic_algorithm/sort.md) +- [动态规划](https://github.com/greyireland/algorithm-pattern/blob/master/basic_algorithm/dp.md) ### 算法思维 🦁 -- [递归思维](advanced_algorithm/recursion.md) -- [滑动窗口思想](advanced_algorithm/slide_window.md) -- [二叉搜索树](advanced_algorithm/binary_search_tree.md) -- [回溯法](advanced_algorithm/backtrack.md) +- [递归思维](https://github.com/greyireland/algorithm-pattern/blob/master/advanced_algorithm/recursion.md) +- [滑动窗口思想](https://github.com/greyireland/algorithm-pattern/blob/master/advanced_algorithm/slide_window.md) +- [二叉搜索树](https://github.com/greyireland/algorithm-pattern/blob/master/advanced_algorithm/binary_search_tree.md) +- [回溯法](https://github.com/greyireland/algorithm-pattern/blob/master/advanced_algorithm/backtrack.md) ## 心得体会 diff --git a/TODO.md b/TODO.md new file mode 100644 index 00000000..044090f8 --- /dev/null +++ b/TODO.md @@ -0,0 +1,8 @@ +# 计划 + +## v1 + +- [ ] 完善文档细节 +- [ ] 工程实现用到的算法解析 +- [ ] 周赛计划 +- [ ] 面试体系计划 diff --git a/practice_algorithm/bplus.md b/practice_algorithm/bplus.md new file mode 100644 index 00000000..9250f6f7 --- /dev/null +++ b/practice_algorithm/bplus.md @@ -0,0 +1 @@ +# b+ tree (MySQL 索引实现) diff --git a/practice_algorithm/data_index.md b/practice_algorithm/data_index.md new file mode 100644 index 00000000..60de3d2a --- /dev/null +++ b/practice_algorithm/data_index.md @@ -0,0 +1 @@ +# 数据索引(kafka 稀疏索引) diff --git a/practice_algorithm/skiplist.md b/practice_algorithm/skiplist.md new file mode 100644 index 00000000..d1f74e41 --- /dev/null +++ b/practice_algorithm/skiplist.md @@ -0,0 +1 @@ +# skiplist(Redis Zset 实现) From 06fbf1e7b2ec95a7438a92d1c8814cb24413ab7e Mon Sep 17 00:00:00 2001 From: greyireland Date: Fri, 19 Jun 2020 22:22:18 +0800 Subject: [PATCH 02/15] update readme --- README.md | 5 ++++- introduction/golang.md | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b00ec9c4..271e2c8b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ 算法模板顾名思义就是刷题的套路模板,掌握了刷题模板之后,刷题也变得好玩起来了~ -> 此项目是自己找工作时,从 0 开始刷 LeetCode 的心得记录,通过各种刷题文章、专栏、视频等总结了一套自己的刷题模板,仅供参考。 +> 此项目是自己找工作时,从 0 开始刷 LeetCode 的心得记录,通过各种刷题文章、专栏、视频等总结了一套自己的刷题模板。 +> 这个模板主要是介绍了一些通用的刷题模板,以及一些常见问题,如到底要刷多少题,按什么顺序来刷题,如何提高刷题效率等。 ## 在线文档 @@ -53,6 +54,8 @@ 开始刷题时,确实是无从下手,因为从序号开始刷,刷到几道题就遇到 hard 的题型,会卡住很久,后面去评论区看别人怎么刷题,也去 Google 搜索最好的刷题方式,发现按题型刷题会舒服很多,基本一个类型的题目,一天能做很多,慢慢刷题也不再枯燥,做起来也很有意思,最后也收到不错的 offer(最后去了宇宙系)。 +回到最开始的问题,面试到底要刷多少题,其实这个取决于你想进什么样公司,你定的目标如果是国内一线大厂,个人感觉大概 200~300 题基本就满足大部分面试需要了。第二个问题是按什么顺序刷及如何提高效率,这个也是本 repo 的目的,给你指定了一个刷题的顺序,以及刷题的模板,有了方向和技巧后,就去动手吧~ 希望刷完之后,你也能自己总结一套属于自己的刷题模板,有所收获,有所成长~ + ## 推荐的刷题路径 按此 repo 目录刷一遍,如果中间有题目卡住了先跳过,然后刷题一遍 LeetCode 探索基础卡片,最后快要面试时刷题一遍剑指 offer。 diff --git a/introduction/golang.md b/introduction/golang.md index 4c0317c6..68c30e3b 100644 --- a/introduction/golang.md +++ b/introduction/golang.md @@ -94,8 +94,8 @@ math.MinInt64 copy ```go -// 删除a[i],可以用 copy 将i+1到末尾的值覆盖到i到末尾-1 -copy(a[i:],b[i+1:]) +// 删除a[i],可以用 copy 将i+1到末尾的值覆盖到i,然后末尾-1 +copy(a[i:],a[i+1:]) a=a[:len(a)-1] // make创建长度,则通过索引赋值 @@ -112,7 +112,7 @@ a=append(a,x) ```go // byte转数字 -s="12345" +s="12345" // s[0] 类型是byte num:=int(s[0]-'0') // 1 str:=string(s[0]) // "1" b:=byte(num+'0') // '1' From 1da0f0229e32b43722642eabe1e03533613d69c2 Mon Sep 17 00:00:00 2001 From: greyireland Date: Fri, 19 Jun 2020 22:26:24 +0800 Subject: [PATCH 03/15] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 271e2c8b..541e4c0a 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ 开始刷题时,确实是无从下手,因为从序号开始刷,刷到几道题就遇到 hard 的题型,会卡住很久,后面去评论区看别人怎么刷题,也去 Google 搜索最好的刷题方式,发现按题型刷题会舒服很多,基本一个类型的题目,一天能做很多,慢慢刷题也不再枯燥,做起来也很有意思,最后也收到不错的 offer(最后去了宇宙系)。 -回到最开始的问题,面试到底要刷多少题,其实这个取决于你想进什么样公司,你定的目标如果是国内一线大厂,个人感觉大概 200~300 题基本就满足大部分面试需要了。第二个问题是按什么顺序刷及如何提高效率,这个也是本 repo 的目的,给你指定了一个刷题的顺序,以及刷题的模板,有了方向和技巧后,就去动手吧~ 希望刷完之后,你也能自己总结一套属于自己的刷题模板,有所收获,有所成长~ +回到最开始的问题,面试到底要刷多少题,其实这个取决于你想进什么样公司,你定的目标如果是国内一线大厂,个人感觉大概 200~300 题基本就满足大部分面试需要了。第二个问题是按什么顺序刷及如何提高效率,这个也是本 **repo** 的目的,给你指定了一个刷题的顺序,以及刷题的模板,有了方向和技巧后,就去动手吧~ 希望刷完之后,你也能自己总结一套属于自己的刷题模板,有所收获,有所成长~ ## 推荐的刷题路径 From b7ffa6ad8e19e1dfd22567da1de56fc5f4a96438 Mon Sep 17 00:00:00 2001 From: greyireland Date: Fri, 19 Jun 2020 22:33:06 +0800 Subject: [PATCH 04/15] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 541e4c0a..7c27db09 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ 算法模板顾名思义就是刷题的套路模板,掌握了刷题模板之后,刷题也变得好玩起来了~ > 此项目是自己找工作时,从 0 开始刷 LeetCode 的心得记录,通过各种刷题文章、专栏、视频等总结了一套自己的刷题模板。 +> > 这个模板主要是介绍了一些通用的刷题模板,以及一些常见问题,如到底要刷多少题,按什么顺序来刷题,如何提高刷题效率等。 ## 在线文档 @@ -54,7 +55,7 @@ 开始刷题时,确实是无从下手,因为从序号开始刷,刷到几道题就遇到 hard 的题型,会卡住很久,后面去评论区看别人怎么刷题,也去 Google 搜索最好的刷题方式,发现按题型刷题会舒服很多,基本一个类型的题目,一天能做很多,慢慢刷题也不再枯燥,做起来也很有意思,最后也收到不错的 offer(最后去了宇宙系)。 -回到最开始的问题,面试到底要刷多少题,其实这个取决于你想进什么样公司,你定的目标如果是国内一线大厂,个人感觉大概 200~300 题基本就满足大部分面试需要了。第二个问题是按什么顺序刷及如何提高效率,这个也是本 **repo** 的目的,给你指定了一个刷题的顺序,以及刷题的模板,有了方向和技巧后,就去动手吧~ 希望刷完之后,你也能自己总结一套属于自己的刷题模板,有所收获,有所成长~ +回到最开始的问题,面试到底要刷多少题,其实这个取决于你想进什么样公司,你定的目标如果是国内一线大厂,个人感觉大概 200 至 300 题基本就满足大部分面试需要了。第二个问题是按什么顺序刷及如何提高效率,这个也是本 repo 的目的,给你指定了一个刷题的顺序,以及刷题的模板,有了方向和技巧后,就去动手吧~ 希望刷完之后,你也能自己总结一套属于自己的刷题模板,有所收获,有所成长~ ## 推荐的刷题路径 From d3525f5ef68d85276f36d9c104c5be0818be234c Mon Sep 17 00:00:00 2001 From: greyireland Date: Fri, 19 Jun 2020 22:44:50 +0800 Subject: [PATCH 05/15] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c27db09..7f3e22b4 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ ![剑指offer](https://img.fuiboom.com/img/leetcode_jzoffer.png) -刷题时间可以合理分配,如果打算准备面试了,建议前面两部分 一个半月 (6 周)时间刷完,最后剑指 offer 半个月刷完,边刷可以边投简历进行面试,遇到不会的不用着急,往模板上套就对了~ +刷题时间可以合理分配,如果打算准备面试了,建议前面两部分 一个半月 (6 周)时间刷完,最后剑指 offer 半个月刷完,边刷可以边投简历进行面试,遇到不会的不用着急,往模板上套就对了,如果面试管给你提示,那就好好做,不要错过这大好机会~ > 注意点:如果为了找工作刷题,遇到 hard 的题如果有思路就做,没思路先跳过,先把基础打好,再来刷 hard 可能效果会更好~ From eaaf92de2742b4e2a06fa3e307dd83579a31dbb8 Mon Sep 17 00:00:00 2001 From: greyireland Date: Sat, 27 Jun 2020 19:44:54 +0800 Subject: [PATCH 06/15] update readme --- README.md | 11 ++++++++++- data_structure/linked_list.md | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7f3e22b4..7395a655 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,17 @@ [我看过的 100 本书](https://github.com/greyireland/awesome-programming-books-1) -## 后续 +## 更新计划 持续更新中,觉得还可以的话点个 **star** 收藏呀 ⭐️~ 【 Github 】[https://github.com/greyireland/algorithm-pattern](https://github.com/greyireland/algorithm-pattern) ⭐️ + +## 完成打卡 + +完成计划之后,可以提交 Pull requests,在下面添加自己的项目仓库,完成自己的算法模板打卡呀~ + +| 完成 | 用户 | 项目地址 | +| ---- | ------------------------------------------------- | ------------------------------------------------------------------- | +| ✅ | [wardseptember](https://github.com/wardseptember) | [notes(Java 实现)](https://github.com/wardseptember/notes) | +| 🕒 | [dashidhy](https://github.com/dashidhy) | [algorithm-pattern-python(Python 实现)](https://github.com/dashidhy/algorithm-pattern-python) | diff --git a/data_structure/linked_list.md b/data_structure/linked_list.md index ebcc1625..8f4a969b 100644 --- a/data_structure/linked_list.md +++ b/data_structure/linked_list.md @@ -379,7 +379,8 @@ func hasCycle(head *ListNode) bool { fast := head.Next slow := head for fast != nil && fast.Next != nil { - if fast.Val == slow.Val { + // 比较指针是否相等(不要使用val比较!) + if fast == slow { return true } fast = fast.Next.Next From d246680a85a3bd0d29d1138b0e82613ef024928b Mon Sep 17 00:00:00 2001 From: thebestwj <55725208+thebestwj@users.noreply.github.com> Date: Sun, 28 Jun 2020 09:46:54 +0800 Subject: [PATCH 07/15] Update stack_queue.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 一个小错误 --- data_structure/stack_queue.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structure/stack_queue.md b/data_structure/stack_queue.md index e1ed723c..6f90a3ef 100644 --- a/data_structure/stack_queue.md +++ b/data_structure/stack_queue.md @@ -513,7 +513,7 @@ func updateMatrix(matrix [][]int) [][]int { ## 总结 - 熟悉栈的使用场景 - - 后出先出,保存临时值 + - 后入先出,保存临时值 - 利用栈 DFS 深度搜索 - 熟悉队列的使用场景 - 利用队列 BFS 广度搜索 From d8caecf530a6b066a7e7fefbdaac4446ca70dabd Mon Sep 17 00:00:00 2001 From: thebestwj <55725208+thebestwj@users.noreply.github.com> Date: Mon, 29 Jun 2020 12:55:16 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20linked=5Flist.md=20?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_structure/linked_list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structure/linked_list.md b/data_structure/linked_list.md index 8f4a969b..db13680d 100644 --- a/data_structure/linked_list.md +++ b/data_structure/linked_list.md @@ -582,6 +582,6 @@ func copyRandomList(head *Node) *Node { - [ ] [sort-list](https://leetcode-cn.com/problems/sort-list/) - [ ] [reorder-list](https://leetcode-cn.com/problems/reorder-list/) - [ ] [linked-list-cycle](https://leetcode-cn.com/problems/linked-list-cycle/) -- [ ] [linked-list-cycle-ii](https://leetcode-cn.com/problems/https://leetcode-cn.com/problems/linked-list-cycle-ii/) +- [ ] [linked-list-cycle-ii](https://leetcode-cn.com/problems/linked-list-cycle-ii/) - [ ] [palindrome-linked-list](https://leetcode-cn.com/problems/palindrome-linked-list/) - [ ] [copy-list-with-random-pointer](https://leetcode-cn.com/problems/copy-list-with-random-pointer/) From 66f34ef026a7e18751e7d9007a6b3c7d7ee260d1 Mon Sep 17 00:00:00 2001 From: Lisheng Zheng Date: Tue, 30 Jun 2020 01:41:25 +0800 Subject: [PATCH 09/15] chore(path): use relative --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7395a655..e76117be 100644 --- a/README.md +++ b/README.md @@ -18,28 +18,28 @@ ### 入门篇 🐶 -- [go 语言入门](https://github.com/greyireland/algorithm-pattern/blob/master/introduction/golang.md) -- [算法快速入门](https://github.com/greyireland/algorithm-pattern/blob/master/introduction/quickstart.md) +- [go 语言入门](./introduction/golang.md) +- [算法快速入门](./introduction/quickstart.md) ### 数据结构篇 🐰 -- [二叉树](https://github.com/greyireland/algorithm-pattern/blob/master/data_structure/binary_tree.md) -- [链表](https://github.com/greyireland/algorithm-pattern/blob/master/data_structure/linked_list.md) -- [栈和队列](https://github.com/greyireland/algorithm-pattern/blob/master/data_structure/stack_queue.md) -- [二进制](https://github.com/greyireland/algorithm-pattern/blob/master/data_structure/binary_op.md) +- [二叉树](./data_structure/binary_tree.md) +- [链表](./data_structure/linked_list.md) +- [栈和队列](./data_structure/stack_queue.md) +- [二进制](./data_structure/binary_op.md) ### 基础算法篇 🐮 -- [二分搜索](https://github.com/greyireland/algorithm-pattern/blob/master/basic_algorithm/binary_search.md) -- [排序算法](https://github.com/greyireland/algorithm-pattern/blob/master/basic_algorithm/sort.md) -- [动态规划](https://github.com/greyireland/algorithm-pattern/blob/master/basic_algorithm/dp.md) +- [二分搜索](./basic_algorithm/binary_search.md) +- [排序算法](./basic_algorithm/sort.md) +- [动态规划](./basic_algorithm/dp.md) ### 算法思维 🦁 -- [递归思维](https://github.com/greyireland/algorithm-pattern/blob/master/advanced_algorithm/recursion.md) -- [滑动窗口思想](https://github.com/greyireland/algorithm-pattern/blob/master/advanced_algorithm/slide_window.md) -- [二叉搜索树](https://github.com/greyireland/algorithm-pattern/blob/master/advanced_algorithm/binary_search_tree.md) -- [回溯法](https://github.com/greyireland/algorithm-pattern/blob/master/advanced_algorithm/backtrack.md) +- [递归思维](./advanced_algorithm/recursion.md) +- [滑动窗口思想](./advanced_algorithm/slide_window.md) +- [二叉搜索树](./advanced_algorithm/binary_search_tree.md) +- [回溯法](./advanced_algorithm/backtrack.md) ## 心得体会 From 31b156684b2e927434f81dd9f50679c1bfd8da7b Mon Sep 17 00:00:00 2001 From: greyireland Date: Tue, 30 Jun 2020 21:27:16 +0800 Subject: [PATCH 10/15] fix href --- data_structure/linked_list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structure/linked_list.md b/data_structure/linked_list.md index 8f4a969b..93127a11 100644 --- a/data_structure/linked_list.md +++ b/data_structure/linked_list.md @@ -390,7 +390,7 @@ func hasCycle(head *ListNode) bool { } ``` -### [linked-list-cycle-ii](https://leetcode-cn.com/problems/https://leetcode-cn.com/problems/linked-list-cycle-ii/) +### [linked-list-cycle-ii](https://leetcode-cn.com/problems/linked-list-cycle-ii/) > 给定一个链表,返回链表开始入环的第一个节点。  如果链表无环,则返回  `null`。 From fa0a942c366d2d44529d5bd491fa85bd1ec38200 Mon Sep 17 00:00:00 2001 From: Hongyuan Du Date: Wed, 1 Jul 2020 01:56:32 -0700 Subject: [PATCH 11/15] finished a python version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e76117be..a09ea4f9 100644 --- a/README.md +++ b/README.md @@ -98,4 +98,4 @@ | 完成 | 用户 | 项目地址 | | ---- | ------------------------------------------------- | ------------------------------------------------------------------- | | ✅ | [wardseptember](https://github.com/wardseptember) | [notes(Java 实现)](https://github.com/wardseptember/notes) | -| 🕒 | [dashidhy](https://github.com/dashidhy) | [algorithm-pattern-python(Python 实现)](https://github.com/dashidhy/algorithm-pattern-python) | +| ✅ | [dashidhy](https://github.com/dashidhy) | [algorithm-pattern-python(Python 实现)](https://github.com/dashidhy/algorithm-pattern-python) | From 9bf951640d8ac2fee56de51d654a9c63fe7dc564 Mon Sep 17 00:00:00 2001 From: Tianxin Dong Date: Thu, 2 Jul 2020 17:24:53 +0800 Subject: [PATCH 12/15] Fix(dp): fix wordBreak solution in dp --- basic_algorithm/dp.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/basic_algorithm/dp.md b/basic_algorithm/dp.md index d251ca7d..9ada08b4 100644 --- a/basic_algorithm/dp.md +++ b/basic_algorithm/dp.md @@ -488,7 +488,11 @@ func wordBreak(s string, wordDict []string) bool { f[0] = true max := maxLen(wordDict) for i := 1; i <= len(s); i++ { - for j := i - max; j < i && j >= 0; j++ { + l := 0 + if i - max > 0 { + l = i - max + } + for j := l; j < i; j++ { if f[j] && inDict(s[j:i]) { f[i] = true break From 40567799e0e815378dc18f16713affac71261a72 Mon Sep 17 00:00:00 2001 From: greyireland Date: Thu, 2 Jul 2020 19:36:10 +0800 Subject: [PATCH 13/15] fix global map --- basic_algorithm/dp.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/basic_algorithm/dp.md b/basic_algorithm/dp.md index 9ada08b4..07f0b018 100644 --- a/basic_algorithm/dp.md +++ b/basic_algorithm/dp.md @@ -486,25 +486,26 @@ func wordBreak(s string, wordDict []string) bool { } f := make([]bool, len(s)+1) f[0] = true - max := maxLen(wordDict) + max,dict := maxLen(wordDict) for i := 1; i <= len(s); i++ { l := 0 if i - max > 0 { l = i - max } for j := l; j < i; j++ { - if f[j] && inDict(s[j:i]) { + if f[j] && inDict(s[j:i],dict) { f[i] = true - break + break } } } return f[len(s)] } -var dict = make(map[string]bool) -func maxLen(wordDict []string) int { + +func maxLen(wordDict []string) (int,map[string]bool) { + dict := make(map[string]bool) max := 0 for _, v := range wordDict { dict[v] = true @@ -512,10 +513,10 @@ func maxLen(wordDict []string) int { max = len(v) } } - return max + return max,dict } -func inDict(s string) bool { +func inDict(s string,dict map[string]bool) bool { _, ok := dict[s] return ok } From b70881e3333dcfbd2e42791fba75b0223f81ffa4 Mon Sep 17 00:00:00 2001 From: greyireland Date: Thu, 2 Jul 2020 23:15:43 +0800 Subject: [PATCH 14/15] fix jump-game-ii --- basic_algorithm/dp.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/basic_algorithm/dp.md b/basic_algorithm/dp.md index 07f0b018..3bdee61b 100644 --- a/basic_algorithm/dp.md +++ b/basic_algorithm/dp.md @@ -356,6 +356,7 @@ func canJump(nums []int) bool { > 你的目标是使用最少的跳跃次数到达数组的最后一个位置。 ```go +// v1动态规划(其他语言超时参考v2) func jump(nums []int) int { // 状态:f[i] 表示从起点到当前位置最小次数 // 推导:f[i] = f[j],a[j]+j >=i,min(f[j]+1) @@ -383,6 +384,26 @@ func min(a, b int) int { } ``` +```go +// v2 动态规划+贪心优化 +func jump(nums []int) int { + n:=len(nums) + f := make([]int, n) + f[0] = 0 + for i := 1; i < n; i++ { + // 取第一个能跳到当前位置的点即可 + // 因为跳跃次数的结果集是单调递增的,所以贪心思路是正确的 + idx:=0 + for idx 给定一个字符串 _s_,将 _s_ 分割成一些子串,使每个子串都是回文串。 From 6259857052bb1ae96b6f2c9960858970c142b6a1 Mon Sep 17 00:00:00 2001 From: shuaibin <1533607721@qq.com> Date: Thu, 30 Jul 2020 11:53:35 +0800 Subject: [PATCH 15/15] add c++ code --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a09ea4f9..3d158d31 100644 --- a/README.md +++ b/README.md @@ -99,3 +99,4 @@ | ---- | ------------------------------------------------- | ------------------------------------------------------------------- | | ✅ | [wardseptember](https://github.com/wardseptember) | [notes(Java 实现)](https://github.com/wardseptember/notes) | | ✅ | [dashidhy](https://github.com/dashidhy) | [algorithm-pattern-python(Python 实现)](https://github.com/dashidhy/algorithm-pattern-python) | +| ✅ | [binzi56](https://github.com/binzi56) | [algorithm-pattern-c(c++ 实现)](https://github.com/binzi56/algorithm-pattern-c) |