diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 4cb2147e..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..8430cfcf --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# XET LOCK +* filter=xet diff=xet merge=xet -text +*.gitattributes filter= +*.xet/** filter= diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 654feed9..00000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -.idea -website/.vuepress/dist -learning \ No newline at end of file diff --git a/.xet/config.toml b/.xet/config.toml new file mode 100644 index 00000000..2675b0c0 --- /dev/null +++ b/.xet/config.toml @@ -0,0 +1,4 @@ +[upstream] +origin_type = "github" +user_name = "Charmve" +repo_name = "hello-algorithm" diff --git a/README.md b/README.md index cb77d325..d945bf9c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,19 @@ +
+
+   ____  _                                        
+  / ___|| |__    __ _  _ __  _ __ ___ __   __ ___ 
+ | |    | '_ \  / _` || '__|| '_ ` _ \\ \ / // _ \
+ | |___ | | | || (_| || |   | | | | | |\ V /|  __/
+  \____||_| |_| \__,_||_|   |_| |_| |_| \_/  \___|                                             
+    
+
+ ## 简介 -English version repo and Gitbook is on [english branch](https://github.com/geekxh/hello-algorithm/tree/english) +English version repo and Gitbook is on [english branch](https://github.com/Charmve/hello-algorithm/tree/english) -> 小浩算法是我在疫情期间完成的一部图解算法题典! 目前共完成 140+ 道高频面试算法题目,总计 40w 字,全部采用漫画图解的方式,简单易懂! +> CharmveAlgo是我在小浩算法基础上整理的一部图解算法题典! 目前共完成 140+ 道高频面试算法题目,总计 40w 字,全部采用漫画图解的方式,简单易懂! +面向 算法小白初中阶读者。所有代码均在 leetcode 上测试运行,可以直接右上角搜索题号。编程语言包括C++、Python、Java、Go。 > > [点击下载](https://www.geekxh.com/0.0.%E5%AD%A6%E4%B9%A0%E9%A1%BB%E7%9F%A5/03.html?3pVd) @@ -10,12 +21,12 @@ English version repo and Gitbook is on [english branch](https://github.com/geekx
扫码回复【进群】可加入我们的万人刷题学习群;回复【999】可直接下载该项目全部资源
包括:一千本开源电子书、各厂面经、百张思维导图、我写的图解算法题典
如果你愿意支持我,可以给项目点个star,我会很感激!
- + 迈微知识星球

- css - html + css + html Statr

@@ -24,12 +35,12 @@ English version repo and Gitbook is on [english branch](https://github.com/geekx ### 本项目包括 -| 👀 [小浩算法图解题典](https://www.geekxh.com/0.0.%E5%AD%A6%E4%B9%A0%E9%A1%BB%E7%9F%A5/03.html?3pVd) | 🐒 [超清思维导图集锦](https://github.com/geekxh/hello-algorithm/tree/master/%E8%B6%85%E6%B8%85%E6%80%9D%E7%BB%B4%E5%AF%BC%E5%9B%BE100%E5%BC%A0) | 📚 [超清电子书一千本](https://github.com/geekxh/hello-algorithm/tree/master/%E6%B8%85%E6%99%B0%E7%89%88%E7%94%B5%E5%AD%90%E4%B9%A61000%E6%9C%AC) | 🚀 [大厂面经汇总指南](https://github.com/geekxh/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87) | +| 👀 [CharmveAlgo图解题典](https://github.com/Charmve/hello-algorithm/tree/master/%E5%B0%8F%E6%B5%A9%E7%AE%97%E6%B3%95%E5%9B%BE%E8%A7%A3100%E9%81%93) | 🐒 [超清思维导图集锦](https://github.com/Charmve/hello-algorithm/tree/master/%E8%B6%85%E6%B8%85%E6%80%9D%E7%BB%B4%E5%AF%BC%E5%9B%BE100%E5%BC%A0) | 📚 [超清电子书一千本](https://github.com/Charmve/hello-algorithm/tree/master/%E6%B8%85%E6%99%B0%E7%89%88%E7%94%B5%E5%AD%90%E4%B9%A61000%E6%9C%AC) | 🚀 [大厂面经汇总指南](https://github.com/Charmve/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87) | | :--- | :---- | :--- | :--- | -| 🍇 [面试:Java](https://github.com/geekxh/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/Java) | 🍉 [面试:Python](https://github.com/geekxh/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/Python) | 🍅 [面试:前端](https://github.com/geekxh/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/%E5%89%8D%E7%AB%AF) | 🍄 [面试:Mysql](https://github.com/geekxh/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/Mysql) | -| 🍖 [面试:架构师](https://github.com/geekxh/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/%E6%9E%B6%E6%9E%84%E5%B8%88) | 🌽 [面试:C](https://github.com/geekxh/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/C%26C%2B%2B) | 🍏 [面试:C++](https://github.com/geekxh/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/C%26C%2B%2B) | 🍐 [面试:机器学习]() | -| 👺 [专栏:学习os](https://github.com/geekxh/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F)| 📺 [专栏:学习linux](https://github.com/geekxh/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/Linux) | 🎅 [专栏:学习mysql](https://github.com/geekxh/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/Mysql) | 📡 [专栏:学习网络](https://github.com/geekxh/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C) | -| 🆎 [专栏:学习设计模式](https://github.com/geekxh/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F)| 📝 [专栏:学习剑指offer](https://github.com/geekxh/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/%E5%89%91%E6%8C%87offer) | | | +| 🍇 [面试:Java](https://github.com/Charmve/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/Java) | 🍉 [面试:Python](https://github.com/Charmve/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/Python) | 🍅 [面试:前端](https://github.com/Charmve/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/%E5%89%8D%E7%AB%AF) | 🍄 [面试:Mysql](https://github.com/Charmve/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/Mysql) | +| 🍖 [面试:架构师](https://github.com/Charmve/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/%E6%9E%B6%E6%9E%84%E5%B8%88) | 🌽 [面试:C](https://github.com/Charmve/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/C%26C%2B%2B) | 🍏 [面试:C++](https://github.com/Charmve/hello-algorithm/tree/master/%E5%A4%A7%E5%8E%82%E9%9D%A2%E7%BB%8F%E6%B1%87%E6%80%BB100%E7%AF%87/C%26C%2B%2B) | 🍐 [面试:机器学习](https://github.com/Charmve/PaperWeeklyAI/tree/master/00_GuideBooksPDF(English%2BChinese)) | +| 👺 [专栏:学习os](https://github.com/Charmve/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F)| 📺 [专栏:学习linux](https://github.com/Charmve/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/Linux) | 🎅 [专栏:学习mysql](https://github.com/Charmve/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/Mysql) | 📡 [专栏:学习网络](https://github.com/Charmve/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C) | +| 🆎 [专栏:学习设计模式](https://github.com/Charmve/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F)| 📝 [专栏:学习剑指offer](https://github.com/Charmve/hello-algorithm/tree/master/%E4%B8%93%E6%A0%8F/%E5%89%91%E6%8C%87offer) | | 🚩 [专栏:Code4FLAG](https://github.com/Charmve/LeetCode4FLAG) | ### 使用指南 @@ -41,35 +52,21 @@ English version repo and Gitbook is on [english branch](https://github.com/geekx 3、如果你还想加入我们的万人刷题群,和我们一起交流,遇见更优秀的人。

- +
-4、当然,也许你就想加我的私人微信: [个人名片](https://www.geekxh.com/contact.jpeg) +4、当然,也许你就想加我的私人微信: Yida_Zhang2 (请备注"github",否则加不了-_-) 注:资料不要贪多,找到适合自己的才重要。 -### 其他资料推荐 - -很多人让我推荐算法视频,我就帮大家找了一个,是前 Facebook 工程师的一个算法视频,主要是应对算法面试。**该视频虽为付费视频,但价格只要9块。** -非常适合基础差的同学。[【点击获取】](https://u.geekbang.org/subject/prioralgorithm?gk_cus_user_wechat=university&utm_source=kolxiaohaosuanfagithub&utm_medium=0911&utm_term=kolxiaohaosuanfagithub0911) - - -
- -下面是另外两个资源:第一个是多线程专项提高,第二个是适合大学生的java就业课。 - -
- - -
我这里再推荐几本算法书籍,大家可以尝试学习 | 书籍名 | 介绍 | |------|------| -| 算法4 | 主要是基础知识,对排序,查找,图,字符串讲解的图非常经典。适合初学者。 | -| 剑指offer | 在有一定刷题经验后进行自我学习。 | -| 算法导论 | 很有名很经典,但更多被用来当作资料查阅,不建议初学者通读。 | +| 算法4 | 主要是基础知识,对排序,查找,图,字符串讲解的图非常经典。适合初学者。 | +| 剑指offer | 在有一定刷题经验后进行自我学习。 | +| 算法导论 | 很有名很经典,但更多被用来当作资料查阅,不建议初学者通读。 | | 算法引论 | 从设计算法的角度思考问题,难度颇大,不适合初学者。 | ### 内容展示 @@ -84,7 +81,7 @@ English version repo and Gitbook is on [english branch](https://github.com/geekx 网站效果:[点击查看](https://www.geekxh.com/demo.png) -### 小浩算法图解题典 +### CharmveAlgo算法图解题典 难度:A 基础 B 进阶 @@ -276,3 +273,46 @@ English version repo and Gitbook is on [english branch](https://github.com/geekx ### License 本项目除部分引用开源技术文档的内容外,大部分为本人原创!欢迎任何以学习为目的的传播,但未授权任何平台进行转载! + +

+*Cite By 小浩geekxh +

+
+ +**** +## Recommend + +另外我在整理一个针对Google, FaceBook, Amazon, LinkedIn, MicroSoft求职的高频100题,按照公司类别和题型两种方式分类,有兴趣或者需要的小伙伴,欢迎来fork! + + LeetCode4FLAG + +🔥 🔥 High frequent interview LeetCode test for FaceBook,Linkedin,Amazon,Google. More importantly, the problems' solutions are provided. Offer, offer, offer! + +

+ + +   + + +   + + +   + + +   +

+ +
+ +

+

+ Version No. + English Version + Chinese Version +

+
+ +[Go to -->](https://github.com/Charmve/LeetCode4FLAG) + +**** diff --git a/website/README.md b/website/README.md deleted file mode 100644 index 5dec6833..00000000 --- a/website/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### 通告 - -小浩算法网站源码已做迁移。 \ No newline at end of file diff --git "a/\344\270\223\346\240\217/\345\211\221\346\214\207offer/03_01_DuplicationInArray/solution.cpp" "b/\344\270\223\346\240\217/\345\211\221\346\214\207offer/03_01_DuplicationInArray/solution.cpp" new file mode 100644 index 00000000..19d41a32 --- /dev/null +++ "b/\344\270\223\346\240\217/\345\211\221\346\214\207offer/03_01_DuplicationInArray/solution.cpp" @@ -0,0 +1,15 @@ +#include +#include + +using namespace std; + +class soluton +{ + +} + +int main(void) +{ + + return -1; +} diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/C&C++/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/C&C++/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" new file mode 100644 index 00000000..f74ef8c4 Binary files /dev/null and "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/C&C++/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/C&C++/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/C&C++/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" deleted file mode 100644 index 896d2cf0..00000000 Binary files "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/C&C++/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" and /dev/null differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Java/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Java/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" new file mode 100644 index 00000000..f74ef8c4 Binary files /dev/null and "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Java/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Java/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Java/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" deleted file mode 100644 index 896d2cf0..00000000 Binary files "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Java/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" and /dev/null differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Mysql/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Mysql/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" new file mode 100644 index 00000000..f74ef8c4 Binary files /dev/null and "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Mysql/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Mysql/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Mysql/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" deleted file mode 100644 index 896d2cf0..00000000 Binary files "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Mysql/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" and /dev/null differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Python/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Python/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" new file mode 100644 index 00000000..f74ef8c4 Binary files /dev/null and "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Python/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Python/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Python/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" deleted file mode 100644 index 896d2cf0..00000000 Binary files "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/Python/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" and /dev/null differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\345\211\215\347\253\257/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\345\211\215\347\253\257/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" new file mode 100644 index 00000000..f74ef8c4 Binary files /dev/null and "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\345\211\215\347\253\257/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201.png" differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\345\211\215\347\253\257/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\345\211\215\347\253\257/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" deleted file mode 100644 index 896d2cf0..00000000 Binary files "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\345\211\215\347\253\257/\350\247\243\345\216\213\345\257\206\347\240\201\345\234\250\350\277\231\351\207\214/\350\247\243\345\216\213\345\257\206\347\240\201\350\277\231\351\207\214 .jpg" and /dev/null differ diff --git "a/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\346\236\266\346\236\204\345\270\210/\350\247\243\345\216\213\345\257\206\347\240\201.png" "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\346\236\266\346\236\204\345\270\210/\350\247\243\345\216\213\345\257\206\347\240\201.png" new file mode 100644 index 00000000..f74ef8c4 Binary files /dev/null and "b/\345\244\247\345\216\202\351\235\242\347\273\217\346\261\207\346\200\273100\347\257\207/\346\236\266\346\236\204\345\270\210/\350\247\243\345\216\213\345\257\206\347\240\201.png" differ diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/README.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/README.md" index 88fde57c..3006bb50 100644 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/README.md" +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/README.md" @@ -1,11 +1,9 @@ -## 小浩算法 +## CharmveAlgo -> 建议通过网站进行学习:[立即学习](https://www.geekxh.com) - -小浩算法是我在疫情期间完成的一部图解算法题典!目前共完成 105道 +CharmveAlgo是我在小浩算法基础上归纳总结的一部图解算法题典!目前共完成 105道 高频面试算法题目,全部采用漫画图解的方式。该教程目前共有 11w 人阅读。 -面向 算法小白初中阶读者。所有代码均在 leetcode 上测试运行,可以直接右上角搜索题号。 +面向 算法小白初中阶读者。所有代码均在 leetcode 上测试运行,可以直接右上角搜索题号。编程语言包括C++、Python、Java、Go。 *** @@ -15,4 +13,4 @@ 2、同时我把自己写的所有内容整理成了一本电子书。下方扫码回复【999】 下载。 -[![图片展示失败,点击查看](https://www.geekxh.com/code.png)](https://www.geekxh.com/code.png) \ No newline at end of file +[![MaiweiCode](https://image.jiqizhixin.com/uploads/editor/d8595d93-e8c9-4abf-91f4-105384736912/%E5%9B%BE%E7%89%8712.jpg)](https://image.jiqizhixin.com/uploads/editor/d8595d93-e8c9-4abf-91f4-105384736912/%E5%9B%BE%E7%89%8712.jpg) diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001.md" deleted file mode 100644 index 3341ac87..00000000 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001.md" +++ /dev/null @@ -1,121 +0,0 @@ - -## 两个数组的交集(350) - - -## 01、题目分析 - -我们先来看一道题目: - -| 第350题:两个数组的交集 | -| ----------------------------------------------------- | -| 给定两个数组,编写一个函数来计算它们的交集。 | - -**示例 1:** - -``` -输入: nums1 = [1,2,2,1], nums2 = [2,2] - -输出: [2,2] -``` - -**示例 2:** - -``` -输入: nums1 = [4,9,5], nums2 = [9,4,9,8,4] - -输出: [4,9] -``` - -说明: - -- 输出结果中每个元素出现的次数,应与元素在两个数组中出现的次数一致。 -- 我们可以不考虑输出结果的顺序。 - -进阶: - -- 如果给定的数组已经排好序呢?将如何优化你的算法呢? - -思路:设定两个为0的指针,比较两个指针的元素是否相等。如果指针的元素相等,我们将两个指针一起向后移动,并且将相等的元素放入空白数组。 - -## 02、题解分析 - -> 首先拿到这道题,我们基本马上可以想到,此题可以看成是一道传统的**映射题(map映射)**,为什么可以这样看呢,因为**我们需找出两个数组的交集元素,同时应与两个数组中出现的次数一致。这样就导致了我们需要知道每个值出现的次数,所以映射关系就成了<元素,出现次数>**。剩下的就是顺利成章的解题。 - -由于该种解法过于简单,我们不做进一步分析,直接给出题解: - -```go -//GO -func intersect(nums1 []int, nums2 []int) []int { - m0 := map[int]int{} - for _, v := range nums1 { - //遍历nums1,初始化map - m0[v] += 1 - } - k := 0 - for _, v := range nums2 { - //如果元素相同,将其存入nums2中,并将出现次数减1 - if m0[v] > 0 { - m0[v] -=1 - nums2[k] = v - k++ - } - } - return nums2[0:k] -} -``` - -这个方法比较简单,相信大家都能看的懂! - -## 03、题目进阶 - -> 题目在进阶问题中问道:如果给定的数组已经排好序呢?你将如何优化你的算法?我们分析一下,假如两个数组都是有序的,分别为:arr1 = [1,2,3,4,4,13],arr2 = [1,2,3,9,10] - -![PNG](./001/1.jpg) - -对于两个已经排序好数组的题,我们可以很容易想到使用双指针的解法~ - -解题步骤如下: - -<1>设定两个为0的指针,**比较两个指针的元素是否相等。** 如果指针的元素相等,我们将两个指针一起向后移动,并且将相等的元素放入空白数组。下图中我们的指针分别指向第一个元素,判断元素相等之后,将相同元素放到空白的数组。 - -![PNG](./001/2.png) - -<2>如果两个指针的元素不相等,**我们将小的一个指针后移。** 图中我们指针移到下一个元素,判断不相等之后,将元素小的指针向后移动,继续进行判断。 - -![PNG](./001/3.png) - -<3>反复以上步骤。 - -![PNG](./001/4.png) - -<4>直到任意一个数组终止。 - -![PNG](./001/5.png) - -## 04、题目解答 - -根据分析,我们很容易得到下面的题解: - -```go -//GO -func intersect(nums1 []int, nums2 []int) []int { - i, j, k := 0, 0, 0 - sort.Ints(nums1) - sort.Ints(nums2) - for i < len(nums1) && j < len(nums2) { - if nums1[i] > nums2[j] { - j++ - } else if nums1[i] < nums2[j] { - i++ - } else { - nums1[k] = nums1[i] - i++ - j++ - k++ - } - } - return nums1[:k] -} -``` - -> 提示:解答中我们并没有创建空白数组,因为遍历后的数组其实就没用了。我们可以**将相等的元素放入用过的数组中,就为我们节省下了空间**。 diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001/350_fig1.gif" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001/350_fig1.gif" new file mode 100644 index 00000000..1566d8fd Binary files /dev/null and "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001/350_fig1.gif" differ diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001_\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206(350).md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001_\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206(350).md" new file mode 100644 index 00000000..8cdb20cc --- /dev/null +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/001_\344\270\244\344\270\252\346\225\260\347\273\204\347\232\204\344\272\244\351\233\206(350).md" @@ -0,0 +1,306 @@ + +## 两个数组的交集(350) + + +## 01、题目分析 + +我们先来看一道题目: + +| 第350题:两个数组的交集 | +| ----------------------------------------------------- | +| 给定两个数组,编写一个函数来计算它们的交集。 | + +**示例 1:** + +``` +输入: nums1 = [1,2,2,1], nums2 = [2,2] + +输出: [2,2] +``` + +**示例 2:** + +``` +输入: nums1 = [4,9,5], nums2 = [9,4,9,8,4] + +输出: [4,9] +``` + +说明: + +- 输出结果中每个元素出现的次数,应与元素在两个数组中出现的次数一致。 +- 我们可以不考虑输出结果的顺序。 + +进阶: + +- 如果给定的数组已经排好序呢?将如何优化你的算法呢? + +思路:设定两个为0的指针,比较两个指针的元素是否相等。如果指针的元素相等,我们将两个指针一起向后移动,并且将相等的元素放入空白数组。 + +## 02、题解分析 + +方法一:哈希表 +> 首先拿到这道题,我们基本马上可以想到,此题可以看成是一道传统的**映射题(map映射)**,为什么可以这样看呢,因为**我们需找出两个数组的交集元素,同时应与两个数组中出现的次数一致。这样就导致了我们需要知道每个值出现的次数,所以映射关系就成了<元素,出现次数>**。剩下的就是顺利成章的解题。 + +![PNG](./001/350_fig1.gif) + +由于该种解法过于简单,我们不做进一步分析,直接给出题解: + +```go +//GO +func intersect(nums1 []int, nums2 []int) []int { + m0 := map[int]int{} + for _, v := range nums1 { + //遍历nums1,初始化map + m0[v] += 1 + } + k := 0 + for _, v := range nums2 { + //如果元素相同,将其存入nums2中,并将出现次数减1 + if m0[v] > 0 { + m0[v] -=1 + nums2[k] = v + k++ + } + } + return nums2[0:k] +} +``` + +这个方法比较简单,相信大家都能看的懂! + +其他编程语言实现: + +C++ +```cpp +class Solution { +public: + vector intersect(vector& nums1, vector& nums2) { + if (nums1.size() > nums2.size()) { + return intersect(nums2, nums1); + } + unordered_map m; + for (int num : nums1) { + ++m[num]; + } + vector intersection; + for (int num : nums2) { + if (m.count(num)) { + intersection.push_back(num); + --m[num]; + if (m[num] == 0) { + m.erase(num); + } + } + } + return intersection; + } +}; +``` +
+ +Python +```python +class Solution: + def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: + if len(nums1) > len(nums2): + return self.intersect(nums2, nums1) + + m = collections.Counter() + for num in nums1: + m[num] += 1 + + intersection = list() + for num in nums2: + if (count := m.get(num, 0)) > 0: + intersection.append(num) + m[num] -= 1 + if m[num] == 0: + m.pop(num) + + return intersection +``` +
+ +Java: + +```java +class Solution { + public int[] intersect(int[] nums1, int[] nums2) { + if (nums1.length > nums2.length) { + return intersect(nums2, nums1); + } + Map map = new HashMap(); + for (int num : nums1) { + int count = map.getOrDefault(num, 0) + 1; + map.put(num, count); + } + int[] intersection = new int[nums1.length]; + int index = 0; + for (int num : nums2) { + int count = map.getOrDefault(num, 0); + if (count > 0) { + intersection[index++] = num; + count--; + if (count > 0) { + map.put(num, count); + } else { + map.remove(num); + } + } + } + return Arrays.copyOfRange(intersection, 0, index); + } +} +``` + +复杂度分析 + +- 时间复杂度:O(m+n),其中 m 和 n 分别是两个数组的长度。需要遍历两个数组并对哈希表进行操作,哈希表操作的时间复杂度是O(1),因此总时间复杂度与两个数组的长度和呈线性关系。 + +- 空间复杂度:O(min(m,n)),其中 m 和 n 分别是两个数组的长度。对较短的数组进行哈希表的操作,哈希表的大小不会超过较短的数组的长度。为返回值创建一个数组 intersection,其长度为较短的数组的长度。 + +## 03、题目进阶 + + +> 题目在进阶问题中问道:如果给定的数组已经排好序呢?你将如何优化你的算法?我们分析一下,假如两个数组都是有序的,分别为:arr1 = [1,2,3,4,4,13],arr2 = [1,2,3,9,10] + +![PNG](./001/1.jpg) + +对于两个已经排序好数组的题,我们可以很容易想到使用双指针的解法~ + +解题步骤如下: + +<1>设定两个为0的指针,**比较两个指针的元素是否相等。** 如果指针的元素相等,我们将两个指针一起向后移动,并且将相等的元素放入空白数组。下图中我们的指针分别指向第一个元素,判断元素相等之后,将相同元素放到空白的数组。 + +![PNG](./001/2.png) + +<2>如果两个指针的元素不相等,**我们将小的一个指针后移。** 图中我们指针移到下一个元素,判断不相等之后,将元素小的指针向后移动,继续进行判断。 + +![PNG](./001/3.png) + +<3>反复以上步骤。 + +![PNG](./001/4.png) + +<4>直到任意一个数组终止。 + +![PNG](./001/5.png) + +## 04、题目解答 + +根据分析,我们很容易得到下面的题解: + +```go +//GO +func intersect(nums1 []int, nums2 []int) []int { + i, j, k := 0, 0, 0 + sort.Ints(nums1) + sort.Ints(nums2) + for i < len(nums1) && j < len(nums2) { + if nums1[i] > nums2[j] { + j++ + } else if nums1[i] < nums2[j] { + i++ + } else { + nums1[k] = nums1[i] + i++ + j++ + k++ + } + } + return nums1[:k] +} +``` + +> 提示:解答中我们并没有创建空白数组,因为遍历后的数组其实就没用了。我们可以**将相等的元素放入用过的数组中,就为我们节省下了空间**。 + +其他语言实现: +C++: + +```cpp +class Solution { +public: + vector intersect(vector& nums1, vector& nums2) { + sort(nums1.begin(), nums1.end()); + sort(nums2.begin(), nums2.end()); + int length1 = nums1.size(), length2 = nums2.size(); + vector intersection; + int index1 = 0, index2 = 0; + while (index1 < length1 && index2 < length2) { + if (nums1[index1] < nums2[index2]) { + index1++; + } else if (nums1[index1] > nums2[index2]) { + index2++; + } else { + intersection.push_back(nums1[index1]); + index1++; + index2++; + } + } + return intersection; + } +}; +``` +
+ +Python: + +```python +class Solution: + def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: + nums1.sort() + nums2.sort() + + length1, length2 = len(nums1), len(nums2) + intersection = list() + index1 = index2 = 0 + while index1 < length1 and index2 < length2: + if nums1[index1] < nums2[index2]: + index1 += 1 + elif nums1[index1] > nums2[index2]: + index2 += 1 + else: + intersection.append(nums1[index1]) + index1 += 1 + index2 += 1 + + return intersection +``` +
+ +Java: + +```java +class Solution { + public int[] intersect(int[] nums1, int[] nums2) { + Arrays.sort(nums1); + Arrays.sort(nums2); + int length1 = nums1.length, length2 = nums2.length; + int[] intersection = new int[Math.min(length1, length2)]; + int index1 = 0, index2 = 0, index = 0; + while (index1 < length1 && index2 < length2) { + if (nums1[index1] < nums2[index2]) { + index1++; + } else if (nums1[index1] > nums2[index2]) { + index2++; + } else { + intersection[index] = nums1[index1]; + index1++; + index2++; + index++; + } + } + return Arrays.copyOfRange(intersection, 0, index); + } +} +``` + +复杂度分析 + +- 时间复杂度:O(mlogm+nlogn),其中 m 和 n 分别是两个数组的长度。对两个数组进行排序的时间复杂度是O(mlogm+nlogn),遍历两个数组的时间复杂度是O(m+n),因此总时间复杂度是O(mlogm+nlogn)。 + +- 空间复杂度:O(min(m,n)),其中 m 和 n 分别是两个数组的长度。为返回值创建一个数组 intersection,其长度为较短的数组的长度。不过在 C++ 中,我们可以直接创建一个 vector,不需要把答案临时存放在一个额外的数组中,所以这种实现的空间复杂度为 O(1)。 + +## 结语 +如果$ \textit{nums}_2$的元素存储在磁盘上,磁盘内存是有限的,并且你不能一次加载所有的元素到内存中。那么就无法高效地对$ \textit{nums}_2$进行排序,因此推荐使用方法一而不是方法二。在方法一中,\textit{nums}2nums2 只关系到查询操作,因此每次读取 $\textit{nums}_2$中的一部分数据,并进行处理即可。 diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/002.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/002_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200(14).md" similarity index 92% rename from "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/002.md" rename to "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/002_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200(14).md" index 1785cbe5..291199a8 100644 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/002.md" +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/002_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200(14).md" @@ -84,3 +84,12 @@ func longestCommonPrefix(strs []string) string { PNG 当然,我们也可以用分治法或者其他方法来解答这道题目。你可以自己尝试尝试哈。我们下期见! + +## 04、多种解法 +- 横向扫描 +- 纵向扫描 +- 分治思想 +- 二分查找 + +请参考链接: +https://leetcode-cn.com/problems/longest-common-prefix/solution/zui-chang-gong-gong-qian-zhui-by-leetcode-solution/ diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/003.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/003_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272(122).md" similarity index 95% rename from "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/003.md" rename to "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/003_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272(122).md" index 71bb745e..dc1c96e5 100644 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/003.md" +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/3.\346\225\260\347\273\204\347\263\273\345\210\227/003_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272(122).md" @@ -101,3 +101,4 @@ func max(a,b int) int { 图解的方式其实在各种算法题中,屡见不鲜。而我们通过图解的方式,也可以抽丝剥茧一样,一层一层剥掉算法题目的外壳,寻找到最直观的解题思路,直捣黄....咳咳,直奔核心。那我们又如何用图解的观察方式,来对本系列的其他题目寻找到一种通用解法,来规避题目中的陷阱呢?浩仔讲算法,我们下期再见喽! +可参考LeetCode官方题解给的方法,链接: https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/solution/mai-mai-gu-piao-de-zui-jia-shi-ji-ii-by-leetcode/ diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/101.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/101_\345\210\240\351\231\244\351\223\276\350\241\250\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271(19).md" similarity index 73% rename from "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/101.md" rename to "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/101_\345\210\240\351\231\244\351\223\276\350\241\250\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271(19).md" index bf36f408..3b67b4bc 100644 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/101.md" +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/101_\345\210\240\351\231\244\351\223\276\350\241\250\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271(19).md" @@ -1,3 +1,4 @@ + ## 删除链表倒数第N个节点(19) @@ -68,6 +69,7 @@ ## 04、题目解答 根据以上分析,我们可以得到下面的题解: +Go: ```go func removeNthFromEnd(head *ListNode, n int) *ListNode { @@ -88,3 +90,68 @@ func removeNthFromEnd(head *ListNode, n int) *ListNode { return result.Next } ``` +
+ +C++: +```cpp +ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) +{ + if(pListHead == nullptr || k == 0) + return nullptr; + + ListNode *pAhead = pListHead; + ListNode *pBehind = nullptr; + + for(unsigned int i = 0; i < k - 1; ++ i) + { + if(pAhead->m_pNext != nullptr) + pAhead = pAhead->m_pNext; + else + { + return nullptr; + } + } + + pBehind = pListHead; + while(pAhead->m_pNext != nullptr) + { + pAhead = pAhead->m_pNext; + pBehind = pBehind->m_pNext; + } + + return pBehind; +} +``` + +
+ +Python: +```python +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode(int x) { val = x; } + * } + */ +class Solution { + public ListNode removeNthFromEnd(ListNode head, int n) { + ListNode dummy = new ListNode(0); + dummy.next = head; + ListNode first = dummy; + ListNode second = dummy; + while (n >= 0) { + first = first.next; + n--; + } + while (first != null) { + first = first.next; + second = second.next; + } + second.next = second.next.next; + return dummy.next; + } +} +``` + diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/102.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/102_\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250(21).md" similarity index 73% rename from "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/102.md" rename to "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/102_\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250(21).md" index 3b9b2908..2c115916 100644 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/102.md" +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/102_\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250(21).md" @@ -51,9 +51,11 @@ l2 = [1,3,4]
-## 03、Go语言示例 +## 03、程序实现 -根据以上分析,我们可以得到下面的题解: +根据以上分析,我们可以得到下面的题解:
+ +Go语言 ```go func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { @@ -78,3 +80,42 @@ func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { return result.Next } ``` +
+ +C++ + +```cpp +class Solution { +public: + ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { + if (l1 == nullptr) { + return l2; + } else if (l2 == nullptr) { + return l1; + } else if (l1->val < l2->val) { + l1->next = mergeTwoLists(l1->next, l2); + return l1; + } else { + l2->next = mergeTwoLists(l1, l2->next); + return l2; + } + } +}; +``` +
+ +Python +```python +class Solution: + def mergeTwoLists(self, l1, l2): + if l1 is None: + return l2 + elif l2 is None: + return l1 + elif l1.val < l2.val: + l1.next = self.mergeTwoLists(l1.next, l2) + return l1 + else: + l2.next = self.mergeTwoLists(l1, l2.next) + return l2 +``` diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/103.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/103_\347\216\257\345\275\242\351\223\276\350\241\250(141).md" similarity index 74% rename from "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/103.md" rename to "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/103_\347\216\257\345\275\242\351\223\276\350\241\250(141).md" index 01772962..2b3e9558 100644 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/103.md" +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/103_\347\216\257\345\275\242\351\223\276\350\241\250(141).md" @@ -171,4 +171,83 @@ func hasCycle(head *ListNode) bool { ## 03、特别说明 -我们常会遇到一些所谓的“简单题目“,然后用着前人留下来的那些”经典题解“迅速作答。在解题的过程中,追求公式化、模板化。当然,这个过程是好的,因为社会、工作、学业要求我们如此!但是,我希望我们也可以留下一些自己的思考,纵然不是最优解,但是是我们自己想到的、创造的!真正在算法题中去收获快乐~ \ No newline at end of file +我们常会遇到一些所谓的“简单题目“,然后用着前人留下来的那些”经典题解“迅速作答。在解题的过程中,追求公式化、模板化。当然,这个过程是好的,因为社会、工作、学业要求我们如此!但是,我希望我们也可以留下一些自己的思考,纵然不是最优解,但是是我们自己想到的、创造的!真正在算法题中去收获快乐~ + +## 04、其他语言实现参考 + +进阶:双指针实现
+ +Java Script: +```javascript +public boolean hasCycle(ListNode head) { + if (head == null || head.next == null) { + return false; + } + ListNode slow = head; + ListNode fast = head.next; + while (slow != fast) { + if (fast == null || fast.next == null) { + return false; + } + slow = slow.next; + fast = fast.next.next; + } + return true; +} +``` +
+ +Python: +```python +class Solution { +public: + bool hasCycle(ListNode *head) { + ListNode *slow = head; + ListNode *fast = head; + while(fast != nullptr) { + fast = fast->next; + if(fast != nullptr) { + fast = fast->next; + } + if(fast == slow) { + return true; + } + slow = slow->next; + } + return nullptr; + } +}; +``` +
+ +C++ +```cpp +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode(int x) : val(x), next(NULL) {} + * }; + */ +class Solution { +public: +bool hasCycle(ListNode* head) +{ + //两个运动员位于同意起点head + ListNode* faster{ head }; //快的运动员 + ListNode* slower{ head }; //慢的运动员 + + if (head == NULL) //输入链表为空,必然不是循环链表 + return false; + + while (faster != NULL && faster->next != NULL) + { + faster = faster->next->next; //快的运动员每次跑两步 + slower = slower->next; //慢的运动员每次跑一步 + if (faster == slower) //他们在比赛中相遇了 + return true; //可以断定是环形道,直道不可能相遇 + } + return false; //快的运动员到终点了,那就是直道,绕圈跑不会有终点 +} +``` diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104/7.jpg" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104/7.jpg" new file mode 100644 index 00000000..383057bc Binary files /dev/null and "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104/7.jpg" differ diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104_\344\270\244\346\225\260\347\233\270\345\212\240(2).md" similarity index 68% rename from "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104.md" rename to "\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104_\344\270\244\346\225\260\347\233\270\345\212\240(2).md" index 16815dc6..a9ffc589 100644 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104.md" +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/4.\351\223\276\350\241\250\347\263\273\345\210\227/104_\344\270\244\346\225\260\347\233\270\345\212\240(2).md" @@ -101,7 +101,107 @@ func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { PNG -## 03、总结 +## 03、其他语言实现 + +Java: +```java +public ListNode addTwoNumbers(ListNode l1, ListNode l2) { + ListNode dummyHead = new ListNode(0); + ListNode p = l1, q = l2, curr = dummyHead; + int carry = 0; + while (p != null || q != null) { + int x = (p != null) ? p.val : 0; + int y = (q != null) ? q.val : 0; + int sum = carry + x + y; + carry = sum / 10; + curr.next = new ListNode(sum % 10); + curr = curr.next; + if (p != null) p = p.next; + if (q != null) q = q.next; + } + if (carry > 0) { + curr.next = new ListNode(carry); + } + return dummyHead.next; +} +``` + +作者:LeetCode
+链接:https://leetcode-cn.com/problems/add-two-numbers/solution/liang-shu-xiang-jia-by-leetcode/ + +
+ +C++: +```cpp +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode(int x) : val(x), next(NULL) {} + * }; + */ +class Solution { +public: + ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { + ListNode* l3 = new ListNode(-1); + ListNode* hl3 = l3; + int c = 0, end1 = 0, end2 = 0; + while (end1 == 0 || end2 == 0 || c == 1) + { + l3->val = (l1->val + l2->val + c) % 10; + c = (l1->val + l2->val + c) / 10; + if (l1->next == NULL) l1->val = 0,end1=1; else l1 = l1->next; + if (l2->next == NULL) l2->val = 0,end2=1; else l2 = l2->next; + if (end1 == 0 || end2 == 0 || c == 1) + { + l3->next = new ListNode(-1); + l3 = l3->next; + } + } + return hl3; + } +}; +``` +PNG + +
+ +Python: +```python +# Definition for singly-linked list. +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + +class Solution: + def addTwoNumbers(self, l1, l2): + """ + :type l1: ListNode + :type l2: ListNode + :rtype: ListNode + """ + r = res = ListNode(0) + carry = 0 + while l1 or l2: + x = l1.val if l1 else 0 + y = l2.val if l2 else 0 + s = carry + x + y + carry = s // 10 + r.next = ListNode(s % 10) + r = r.next + if l1: + l1 = l1.next + if l2: + l2 = l2.next + if carry > 0: + r.next = ListNode(1) + return res.next +``` +
+ +## 04、总结 > 1950年6月19日,毛泽东写信给当时的教育部部长马叙伦:“要各校注意健康第一,学习第二。营养不足,宜酌增经费。”1951年9月底,毛泽东接见安徽参加国庆的代表团,代表团成员中有渡江小英雄马三姐。毛泽东关切地问她念书情况,还送她一本精美的笔记本,并且在扉页上题词:**好好学习,天天向上**。这8个字的题词迅速在全国传播开来。 diff --git "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/README.md" "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/README.md" index e5123668..3c4f7db3 100644 --- "a/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/README.md" +++ "b/\345\260\217\346\265\251\347\256\227\346\263\225\345\233\276\350\247\243100\351\201\223/sourcefile/README.md" @@ -6,6 +6,6 @@ --- -#### 该目录源文件将不再更新,新的内容请移驾到我的个人网站进行学习或者下载 +#### 该目录源文件将不再更新,新的内容请移驾到新的repo进行学习或者下载 -[访问网站学习](https://www.geekxh.com) \ No newline at end of file +[访问学习](https://github.com/Charmve/LeetCode4FLAG) diff --git "a/\346\270\205\346\231\260\347\211\210\347\224\265\345\255\220\344\271\2461000\346\234\254/README.md" "b/\346\270\205\346\231\260\347\211\210\347\224\265\345\255\220\344\271\2461000\346\234\254/README.md" index 3b50abec..5350c7fc 100644 --- "a/\346\270\205\346\231\260\347\211\210\347\224\265\345\255\220\344\271\2461000\346\234\254/README.md" +++ "b/\346\270\205\346\231\260\347\211\210\347\224\265\345\255\220\344\271\2461000\346\234\254/README.md" @@ -8,9 +8,10 @@ 提取码:请下方扫码回复【book】进行获取 -
- -
+
+ +
△微信扫一扫,关注我
+
![](./book_1000.png) diff --git "a/\350\266\205\346\270\205\346\200\235\347\273\264\345\257\274\345\233\276100\345\274\240/img/code.png" "b/\350\266\205\346\270\205\346\200\235\347\273\264\345\257\274\345\233\276100\345\274\240/img/code.png" deleted file mode 100644 index 14bab389..00000000 Binary files "a/\350\266\205\346\270\205\346\200\235\347\273\264\345\257\274\345\233\276100\345\274\240/img/code.png" and /dev/null differ diff --git "a/\350\266\205\346\270\205\346\200\235\347\273\264\345\257\274\345\233\276100\345\274\240/img/polarisxu-qrcode-m.jpg" "b/\350\266\205\346\270\205\346\200\235\347\273\264\345\257\274\345\233\276100\345\274\240/img/polarisxu-qrcode-m.jpg" index be466d72..ddfb24a1 100644 Binary files "a/\350\266\205\346\270\205\346\200\235\347\273\264\345\257\274\345\233\276100\345\274\240/img/polarisxu-qrcode-m.jpg" and "b/\350\266\205\346\270\205\346\200\235\347\273\264\345\257\274\345\233\276100\345\274\240/img/polarisxu-qrcode-m.jpg" differ