Skip to content

算法训练营(深圳站)第一周作业 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GeekUniversity opened this issue Jun 1, 2019 · 206 comments
Open

算法训练营(深圳站)第一周作业 #1

GeekUniversity opened this issue Jun 1, 2019 · 206 comments

Comments

@GeekUniversity
Copy link
Contributor

GeekUniversity commented Jun 1, 2019

要求

  1. 每周至少完成给定题目中的两道算法题
  2. 围绕每周重点学习的算法知识点,撰写一篇有观点和思考的技术文章(字数不限)
  3. 第一周作业特别要求:根据你的理解和掌握程度,绘制一张属于你自己的数据结构和算法知识脑图。脑图请放在学习总结中一起提交。

注意事项

  1. 下面列出的题目中,按照知识点进行了简单分类,但并不意味着使用相应的数据结构或算法一定是解决该题目的最优解,这样分类只是为了方便大家有针对性的练习;
  2. 有的题目可能需要结合多个算法或数据结构进行求解。

第一周题目

数组、链表

简单:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
简单:https://leetcode-cn.com/problems/rotate-array/
简单:https://leetcode-cn.com/problems/merge-two-sorted-lists/
简单:https://leetcode-cn.com/problems/merge-sorted-array/
中等:https://leetcode-cn.com/problems/swap-nodes-in-pairs/
中等:https://leetcode-cn.com/problems/3sum/

Map & Set

简单:https://leetcode-cn.com/problems/valid-anagram/
中等:https://leetcode-cn.com/problems/group-anagrams/

堆栈、队列

简单:https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/
简单:https://leetcode-cn.com/problems/remove-outermost-parentheses/
困难:https://leetcode.com/problems/largest-rectangle-in-histogram/
困难:https://leetcode.com/problems/trapping-rain-water/

二分查找

简单:https://leetcode-cn.com/problems/arranging-coins/
中等:https://leetcode-cn.com/problems/powx-n/
困难:https://leetcode-cn.com/problems/dungeon-game/

递归

简单:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
简单:https://leetcode-cn.com/problems/symmetric-tree/
简单:https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/
简单:https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/
简单:https://leetcode-cn.com/problems/binary-tree-paths/
简单:https://leetcode-cn.com/problems/range-sum-of-bst/
中等:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/

作业提交规则

  1. 在提交作业之前,请先阅读这里的 README 文档:
    https://github.com/algorithm002/algorithm/blob/master/README.md
  2. 然后在此 Issues 下按照如下格式回复(示例见一楼):

#作业提交
学号:
username:
代码作业:(填写自己仓库下对应的作业链接即可,同时记得给本仓库提交 pull request)
学习总结:发表自己本周的学习感言 issues,并提交链接,issues 标题格式:“【学号后三位-week1】+文章标题”,格式参考:#2
使用语言:

@GeekUniversity
Copy link
Contributor Author

#作业提交
学号:000
username:GeekUniversity
代码作业:https://github.com/GeekUniversity/assignment01/blob/master/helloworld.py
学习总结:#2
使用语言:Python

@GeekUniversity
Copy link
Contributor Author

#作业提交
学号:000
username:GeekUniversity
代码作业:https://github.com/GeekUniversity/assignment01/blob/master/helloworld.py
学习总结:#2
使用语言:Python

(通过Quote reply,在这里写下你对某位同学代码作业或学习总结的点评)

@SymerBoy
Copy link
Contributor

SymerBoy commented Jun 20, 2019

#作业提交
学号:037
username:孙勇猛
代码作业:https://github.com/symerSun/algorithm/tree/master/Week_01/id_37
学习总结:#5
使用语言:JAVA

@suhuabing
Copy link
Contributor

#作业提交
学号:035
username:苏华兵
代码作业:https://github.com/suhuabing/algorithm/tree/master/Week_01/id_35
学习总结:#8
使用语言:JAVA

@SymerBoy
Copy link
Contributor

#作业提交
学号:035
username:苏华兵
代码作业:https://github.com/suhuabing/algorithm/tree/master/Week_01/id_35
学习总结:#8
使用语言:JAVA

对于对称2叉树(leetCode 101)
if判断可缩进为一行,
if(left == null && right == null) return true; else if(left == null || right == null) return false;

另外对于如果当前节点值不相同直接返回false即可,否则,直接双层下探;
return left.val != right.val ? false:isSame(left.left,right.right) && isSame(left.right,right.left);
思路其实是相同的.只是还有表达方式不同;
ps:没有同学提交作业,只能先挑一个开刀了;

@suhuabing
Copy link
Contributor

#作业提交
学号:037
username:孙勇猛
代码作业:https://github.com/symerSun/algorithm/tree/master/Week_01/id_37
学习总结:#5
使用语言:JAVA

1、 LeetCode_104_37,else这个代码可以去除,因为如果root == null就已经返回了。减少代码量
2、 LeetCode_441_37,可以使用二分查询,降低时间复杂度。因为结果是一定要符合阶梯层级并且消耗总数在n范围内。所以,利用二分查找,如果最终的中间那个数的消耗总数等于n,那就直接返回中间的那个数即可。如果不是,那就继续二分查找,到时 最后一个中间数时,如果还是没有等于的,那我们就取左边后退一位的那个数。

@HelloThisWorld
Copy link
Contributor

HelloThisWorld commented Jun 22, 2019

#作业提交
学号:024
username:HelloThisWorld
代码作业:https://github.com/HelloThisWorld/algorithm/tree/master/Week_01/id_24
学习总结:#14
使用语言:Java

@libinyl
Copy link
Contributor

libinyl commented Jun 22, 2019

作业提交

学号:040
username:libinyl
代码作业:https://github.com/libinyl/algorithm/tree/master/Week_01/id_40
学习总结:#18
使用语言:Python

@yyyyfan
Copy link
Contributor

yyyyfan commented Jun 22, 2019

#作业提交
学号:033
username:杨帆
代码作业:https://github.com/yyyyfan/algorithm/tree/master/Week_01/id_33
学习总结:#20
使用语言:Go

@yyyyfan
Copy link
Contributor

yyyyfan commented Jun 22, 2019

#作业提交
学号:037
username:孙勇猛
代码作业:https://github.com/symerSun/algorithm/tree/master/Week_01/id_37
学习总结:#5
使用语言:JAVA

二叉搜索树缺少第三个条件, 它的左、右子树也分别为二叉搜索树

@yyyyfan
Copy link
Contributor

yyyyfan commented Jun 22, 2019

#作业提交
学号:035
username:苏华兵
代码作业:https://github.com/suhuabing/algorithm/tree/master/Week_01/id_35
学习总结:#8
使用语言:JAVA

针对Week_01/id_35/LeetCode_49_035.java中代码

            List<String> list = map.get(String.valueOf(sortArray));
            if (list == null) {
                list = new ArrayList<String>();
            }
            list.add(strs[i]);
            map.put(String.valueOf(sortArray), list);

可优化为

            List<String> list = map.computeIfAbsent(String.valueOf(sortArray), item -> new ArrayList<String>());
            list.add(strs[i]);

@GeekUniversity GeekUniversity pinned this issue Jun 22, 2019
@wusuizhi
Copy link

#作业提交
学号:030
username:吴穗智
代码作业:https://github.com/zhomgwu/algorithm/tree/master/Week_01/id_30
学习总结:#31
使用语言:CPP

@kkkkk0cool
Copy link
Contributor

#作业提交
学号:023
username:kkkkk0cool
代码作业:https://github.com/kkkkk0cool/algorithm/tree/master/Week_01/id_23
学习总结:#33
使用语言:c++

@scytlaimin
Copy link

scytlaimin commented Jun 23, 2019

#作业提交
学号:032
用户名:scytlaimin
代码作业:https://github.com/scytlaimin/algorithm/tree/master/Week_01/id_32
学习总结:#34
使用语言:JAVA

@xsplus
Copy link
Contributor

xsplus commented Jun 23, 2019

#作业提交
学号:006
username:xsplus
代码作业:https://github.com/xsplus/algorithm/tree/master/Week_01/id_6
学习总结:#40
使用语言:Go

@katecqc
Copy link
Contributor

katecqc commented Jun 23, 2019

学号:05
username:陈巧婵
代码作业:https://github.com/katecqc/algorithm/tree/master/Week_01/id_5
学习总结:#35
使用语言:Javascript

@Peng282
Copy link
Contributor

Peng282 commented Jun 23, 2019

#作业提交
学号:047
用户名:Peng282
代码作业:https://github.com/Peng282/algorithm/tree/master/Week_01/id_47
学习总结:#47
使用语言:JAVA

@wu360
Copy link
Contributor

wu360 commented Jun 23, 2019

#作业提交
学号:042
username:winn
代码作业:https://github.com/wu360/algorithm-1/tree/master/Week_01/id_42
学习总结:#78
使用语言:Java

@pizhihui
Copy link

pizhihui commented Jun 23, 2019

#作业提交
学号:012
username:pizhihui
代码作业:https://github.com/pizhihui/algorithm/tree/master/Week_01/id_12
学习总结:#46
使用语言:Java

@pizhihui
Copy link

pizhihui commented Jun 23, 2019

#作业提交
学号:035
username:苏华兵
代码作业:https://github.com/suhuabing/algorithm/tree/master/Week_01/id_35
学习总结:#8
使用语言:JAVA

24 题的 Swap Nodes in Paris 的常规解法需要四个指针,绕来绕去,有点晕,不过可以考虑递归解法。还在研究中

@pizhihui
Copy link

pizhihui commented Jun 23, 2019

#作业提交
学号:000
username:HelloThisWorld
代码作业:https://github.com/HelloThisWorld/algorithm/tree/master/Week_01/id_24
学习总结:#14
使用语言:Java

Merge-Two-Sorted-Lists递归的解法不错呀,学习下新的思路,我都是用简历指针,各种穿针引线用的,有时候比较头晕

@pizhihui
Copy link

学号:05
username:陈巧婵
代码作业:https://github.com/katecqc/algorithm/tree/master/Week_01/id_5
学习总结:#35
使用语言:Javascript

js 代码好简洁,正在研究中。。。。

@pizhihui
Copy link

#作业提交
学号:032
用户名:scytlaimin
代码作业:https://github.com/scytlaimin/algorithm/tree/master/Week_01/id_32
学习总结:#32
使用语言:JAVA

sum of two 的解法,两个循环的 map 和一个循环的 map 还是有时间差别哦。效率还是差距很大,不过在理解方面还是相反的。HashMap 的解题思路在很多方面都有借鉴了。

@Kilien
Copy link
Contributor

Kilien commented Jun 23, 2019

#作业提交
学号:001
username:庄棨帆
代码作业:https://github.com/KiLien/algorithm/tree/master/Week_01/id_1
学习总结:#47
使用语言:Python
review:3005333504

@pizhihui
Copy link

#作业提交
学号:035
username:苏华兵
代码作业:https://github.com/suhuabing/algorithm/tree/master/Week_01/id_35
学习总结:#8
使用语言:JAVA

merge sorted array 那道题,拷贝数组和排序都需要耗费时间,我这里的思路好像指针挪动可以弄。目前还没想到具体解法。

@suhuabing
Copy link
Contributor

#作业提交
学号:032
用户名:scytlaimin
代码作业:https://github.com/scytlaimin/algorithm/tree/master/Week_01/id_32
学习总结:#32
使用语言:JAVA

1、LeetCode_1_32,第18行中的 index != i 这个条件是不需要的,因为i是递增的map中的value与i肯定是不一致的,并且,只要target - num[i]作为map的key获取值存在,就说明当前这个值肯定和map那个值两个相加是等于target了。

@suhuabing
Copy link
Contributor

#作业提交
学号:042
username:winn
代码作业:https://github.com/wu360/algorithm-1/tree/master/Week_01/id_42
学习总结:
使用语言:Java

1、Solution101,第40行中的else其实不用的,因为如果if满足就已经return了;
2、Solution111,第34开始,如果左子树为空,说明右子树不为空,那就直接return右子树直接下钻就好了,不需要再判断左右子树的最小深度了。如果右子树为空,说明左子树不为空,同理。能执行到最后的,说明左右子树都不为空,那才左右子树都下钻。

@suhuabing
Copy link
Contributor

#作业提交
学号:012
username:pizhihui
代码作业:https://github.com/pizhihui/algorithm/tree/master/Week_01/id_12
学习总结:#46
使用语言:Java

LeetCode.104.maximum-depth-of-binary-tree.java中17、18行可以直接合成一行,因为新的变量都没地方用了,
return (leftMaxDepth > rightMaxDepth) ? leftMaxDepth + 1 : rightMaxDepth + 1;

@suhuabing
Copy link
Contributor

学号:05
username:陈巧婵
代码作业:https://github.com/katecqc/algorithm/tree/master/Week_01/id_5
学习总结:#35
使用语言:Javascript

js写法挺好的,也够简洁,学习了!

@kkkkk0cool
Copy link
Contributor

kkkkk0cool

没错,是这个理

@kkkkk0cool
Copy link
Contributor

学号:05
username:陈巧婵
代码作业:https://github.com/katecqc/algorithm/tree/master/Week_01/id_5
学习总结:#35
使用语言:Javascript

总结写的很励志,加油

@kkkkk0cool
Copy link
Contributor

脑图画的相当厉害,已保存到本地

@heeheehaha45
Copy link
Contributor

#作业提交
学号:035
username:苏华兵
代码作业:https://github.com/suhuabing/algorithm/tree/master/Week_01/id_35
学习总结:#8
使用语言:JAVA

  1. 二叉树的最小深度
    这一段是可以删去的:
    if (root.left == null && root.right == null) { // 如果左右子树都没有值了,说明已经到了叶子节点了
    return 1;
    }
    因为最基本情况是if (root == null) { return 0; } , 你已经写了, 所以叶子节点不是最基本情况, 可以不用特别处理 :)

@heeheehaha45
Copy link
Contributor

#作业提交
学号:024
username:HelloThisWorld
代码作业:https://github.com/HelloThisWorld/algorithm/tree/master/Week_01/id_24
学习总结:#14
使用语言:Java

很精简呢!

@heeheehaha45
Copy link
Contributor

#作业提交
学号:037
username:孙勇猛
代码作业:https://github.com/symerSun/algorithm/tree/master/Week_01/id_37
学习总结:#5
使用语言:JAVA

很精简呢!

@heeheehaha45
Copy link
Contributor

#作业提交
学号:020
username:潘广
代码作业:https://github.com/liangcha/algorithm/tree/master/Week_01/id_20
学习总结:#82
使用语言:Java

很用心的每题写了多种解法, 赞!

@heeheehaha45
Copy link
Contributor

#作业提交
学号:023
username:kkkkk0cool
代码作业:https://github.com/kkkkk0cool/algorithm/tree/master/Week_01/id_23
学习总结:#33
使用语言:c++

LeetCode_783_23, LeetCode_104_23,LeetCode_111_23这三题, 你的解法是可行的, 但应该有更短解法 :)

@Peng282
Copy link
Contributor

Peng282 commented Jul 21, 2019

#作业提交
学号:030
username:吴穗智
代码作业:https://github.com/zhomgwu/algorithm/tree/master/Week_01/id_30
学习总结:#31
使用语言:CPP

这个算法的弄通的过程是这样的,对于程序猿来讲,太多的时候,逻辑以及算法的步骤大都很难一步到位,都是在debug的过程。但是debug的次数多了,这些逻辑会得到总结,成为了内功,后面处理这种问题的速度就会越来越快了。共勉!

@Peng282
Copy link
Contributor

Peng282 commented Jul 21, 2019

#作业提交
学号:016
username:XHShirley
代码作业:https://github.com/XHShirley/algorithm/tree/master/Week_01/id_16
学习总结:#68
使用语言:JAVA
5篇 review:
#1
#2
#3
#4
#5

shirley这周题做的很多,点赞

这个手绘的脑图,有点意思。

@Peng282
Copy link
Contributor

Peng282 commented Jul 21, 2019

#作业提交
学号:023
username:kkkkk0cool
代码作业:https://github.com/kkkkk0cool/algorithm/tree/master/Week_01/id_23
学习总结:#33
使用语言:c++

LeetCode_101_23.cpp第 4 5 行可以去掉吧~

不能去掉,如果去掉就会core了

对于递归的总结,完全赞同,重要的是如何习惯和适应以及总结这种总结,总结出重复简单的重复子问题。

@Peng282
Copy link
Contributor

Peng282 commented Jul 21, 2019

#作业提交
学号:032
用户名:scytlaimin
代码作业:https://github.com/scytlaimin/algorithm/tree/master/Week_01/id_32
学习总结:#32
使用语言:JAVA

嗨~同学!谢谢你的总结。一开始刷题,因为还有没有适应思维方式,是会比较慢的~ 万事开头难!上坡是最累的,坚持下去就会好起来的,加油~!

我突然发现你的脑图比我的好看,这算不算点评,哈哈哈!

@cc1901
Copy link

cc1901 commented Jul 21, 2019

#作业提交
学号:037
username:孙勇猛
代码作业:https://github.com/symerSun/algorithm/tree/master/Week_01/id_37
学习总结:#5
使用语言:JAVA

可以考虑采用guard,如果if return,就不需要else

@cc1901
Copy link

cc1901 commented Jul 21, 2019

https://github.com/suhuabing/algorithm/tree/master/Week_01/id_35

isSymmetric 里递归method的名字可以考虑改一下,实际并不是判断isSame而是对称,可以还叫isSymmetric或者isMirror, 最后一行太长了,可以考虑每个条件一行

@cc1901
Copy link

cc1901 commented Jul 21, 2019

#作业提交
学号:1906019
username:chenjiajuntime
代码作业:https://github.com/chenjiajuntime/algorithm/tree/master/Week_01/id_19
学习总结:#97
使用语言:java

可以考虑用ArrayDeque做stack

@cc1901
Copy link

cc1901 commented Jul 21, 2019

#作业提交
学号:003
username:钟作敏
代码作业:https://github.com/knowledgeAlan/algorithm/tree/master/Week_01/id_3
学习总结:#27
使用语言 JAVA
review:
#33
#35
#31
#8
#25

49题代码略冗余

if(!hashMap.containsKey(String.valueOf(chars))){
               List<String> tempList = new ArrayList<>();
               tempList.add(s);
               hashMap.put(String.valueOf(chars),tempList);
           }else {
               hashMap.get(String.valueOf(chars)).add(s);
           }

考虑用以下代码

  List<String> value = hashMap.computeIfAbsent(String.valueOf(chars),
                                    (key) -> new ArrayList<>());
  value.add(s);

@hu5980
Copy link

hu5980 commented Jul 21, 2019

#作业提交
学号:029
username:胡光耀
代码作业:https://github.com/hu5980/algorithm/tree/master/Week_01/id_29
使用语言:Swift

总结:#51

@cc1901
Copy link

cc1901 commented Jul 21, 2019

#作业提交
学号:032
用户名:scytlaimin
代码作业:https://github.com/scytlaimin/algorithm/tree/master/Week_01/id_32
学习总结:#34
使用语言:JAVA

26题的写法简介明了, 有指导意义

@hu5980
Copy link

hu5980 commented Jul 21, 2019

作业提交

学号:040
username:libinyl
代码作业:https://github.com/libinyl/algorithm/tree/master/Week_01/id_40
学习总结:#18
使用语言:Python

脑图画的相当厉害

@13474129340
Copy link
Contributor

作业提交

学号:040
username:libinyl
代码作业:https://github.com/libinyl/algorithm/tree/master/Week_01/id_40
学习总结:#18
使用语言:Python

刷题不少,分析的很到位,get

@13474129340
Copy link
Contributor

#作业提交
学号:023
username:kkkkk0cool
代码作业:https://github.com/kkkkk0cool/algorithm/tree/master/Week_01/id_23
学习总结:#33
使用语言:c++

代码很干净,题目做的不少啊,这个学习笔记很全面,总结的的很好

@13474129340
Copy link
Contributor

学号:05
username:陈巧婵
代码作业:https://github.com/katecqc/algorithm/tree/master/Week_01/id_5
学习总结:#35
使用语言:Javascript

学习了js写法,这个数据结构图很全面啊,包括优缺点都有,先mark下来了

@13474129340
Copy link
Contributor

#作业提交
学号:029
username:胡光耀
代码作业:https://github.com/hu5980/algorithm/tree/master/Week_01/id_29
使用语言:Swift

学习下swift写法

@13474129340
Copy link
Contributor

#作业提交
学号:033
username:杨帆
代码作业:https://github.com/yyyyfan/algorithm/tree/master/Week_01/id_33
学习总结:#20
使用语言:Go

体量很大啊,学习下Go写法

@wenicaicai
Copy link
Contributor

#作业提交
学号:059
username:杨永财
代码作业:https://github.com/wenicaicai/algorithm/tree/master/Week_01/id_59
学习总结:#320
使用语言:C#

@SUNFOLWER
Copy link
Contributor

#作业提交
学号:035
username:苏华兵
代码作业:https://github.com/suhuabing/algorithm/tree/master/Week_01/id_35
学习总结:#8
使用语言:JAVA

注释详尽,代码写得很好哦

@SUNFOLWER
Copy link
Contributor

#作业提交
学号:033
username:杨帆
代码作业:https://github.com/yyyyfan/algorithm/tree/master/Week_01/id_33
学习总结:#20
使用语言:Go

做了好多题目啊哈哈,了解一下go

@SUNFOLWER
Copy link
Contributor

作业提交

学号:040
username:libinyl
代码作业:https://github.com/libinyl/algorithm/tree/master/Week_01/id_40
学习总结:#18
使用语言:Python

脑图画的相当厉害

做了很多题目哦,学习一下python写法

@SUNFOLWER
Copy link
Contributor

#作业提交
学号:023
username:kkkkk0cool
代码作业:https://github.com/kkkkk0cool/algorithm/tree/master/Week_01/id_23
学习总结:#33
使用语言:c++

做了好多题目啊,和我一样努力哈哈

@SUNFOLWER
Copy link
Contributor

#作业提交
学号:001
username:庄棨帆
代码作业:https://github.com/KiLien/algorithm/tree/master/Week_01/id_1
学习总结:#47
使用语言:Python
review:3005333504

python写法挺有趣的,学习一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests