ARTS是什么? Algorithm:每周至少做一个LeetCode的算法题 Review:阅读并点评至少一篇英文技术文章 Tip:学习至少一个技术技巧,总结和归纳日常工作中遇到的知识点 Share:分享一篇有观点和思考的技术文章
Algorithm
完成leetcode算法第559题。
利用深度优先算法获取树的最大深度。
import java.util.Arrays;
import java.util.List;
/**
* 给定一个 N 叉树,找到其最大深度。
* 最大深度是指从根节点到最远叶子节点的最长路径上的节点总数。
* N 叉树输入按层序遍历序列化表示,每组子节点由空值分隔(请参见示例)。
*
* @author ouyb01
* @date 2021/11/21 18:20
*/
public class MaxTreeDepth559 {
public static void main(String[] args) {
MaxTreeDepth559 example = new MaxTreeDepth559();
Node node5 = new Node(5);
Node node6 = new Node(6);
Node node3 = new Node(3, Arrays.asList(node5, node6));
Node node2 = new Node(2);
Node node4 = new Node(4);
Node root = new Node(1, Arrays.asList(node3, node2, node4));
System.out.println(example.maxDepth(root));
}
public int maxDepth(Node root) {
if (root == null) {
return 0;
}
int maxDepth = 0;
List<Node> children = root.children;
if (children != null) {
for (Node child : children) {
int childDepth = maxDepth(child);
maxDepth = Math.max(maxDepth, childDepth);
}
}
return maxDepth + 1;
}
}
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, List<Node> _children) {
val = _val;
children = _children;
}
}
Review
API Architecture — Design Best Practices for REST APIs
best practices for REST APIs, summarized as follows:
- learn what is get/post/put/delete
- do not return plain text
- do not use verbs in URIs
- use plural nouns for resources
- return the error details in the response body
- pay special attention to HTTP status codes
- use HTTP status codes consistently
- do not nest resources
- handle trailing slashes gracefully
- make use of the querystring for filterring and pagination
- know the diffrence between 401 and 403
- make good use of HTTP 202
- use a web framework specialized in REST APIs
Tip
MySQL相关:
- 只要定义了字节长度,那么自增id就有上限
- 自增id达到上限后:在申请下一个id时,得到的值保持不变
针对上一条,应该在 InnoDB 表中主动创建自增主键。因为,表自增 id 到达上限后,再插入数据时报主键冲突错误,是更能被接受的
Share
学会思考:从搜索引擎得到答案后,要学会去思考为什么是这样的,勤加思考后,很多知识点是可以串起来的
- 学会思考:对现在大量繁杂的信息需要有自己的判断能力,那些是对自己有帮助的。然后对其进行提炼总结,只有自己总结后的东西才是自己的。
- 持之以恒:计算机行业是一个需要大量学习的行业,我们不可能短时间内学习大量的知识。我们要有对自己合理的认知,在不同的阶段做不同的事,然后把它坚持下去。
- 提高认知
- 寻找一手信息
- 寻找高质量信息
- 寻找高密度信息
- 知识图
- 了解知识的缘由,知其然之后就不是死记硬背的事了
- 总结自己的方法。很多问题的解决是有套路可循的,比如算法有深度、广度优先等。学会总结自己的方法后,很多事情都是事半功倍。
Finish
预计完成时间:2021.11.15 ~ 2021.11.21
实际完成时间:2021.11.21
这周加了一整周的班:程序员不能只是写代码,对业务的合理性也要有自己的看法,要更加敏感才行。