ARTS是什么? Algorithm:每周至少做一个LeetCode的算法题 Review:阅读并点评至少一篇英文技术文章 Tip:学习至少一个技术技巧,总结和归纳日常工作中遇到的知识点 Share:分享一篇有观点和思考的技术文章

Algorithm

完成leetcode算法第559题。
利用深度优先算法获取树的最大深度。

  1. import java.util.Arrays;
  2. import java.util.List;
  3. /**
  4. * 给定一个 N 叉树,找到其最大深度。
  5. * 最大深度是指从根节点到最远叶子节点的最长路径上的节点总数。
  6. * N 叉树输入按层序遍历序列化表示,每组子节点由空值分隔(请参见示例)。
  7. *
  8. * @author ouyb01
  9. * @date 2021/11/21 18:20
  10. */
  11. public class MaxTreeDepth559 {
  12. public static void main(String[] args) {
  13. MaxTreeDepth559 example = new MaxTreeDepth559();
  14. Node node5 = new Node(5);
  15. Node node6 = new Node(6);
  16. Node node3 = new Node(3, Arrays.asList(node5, node6));
  17. Node node2 = new Node(2);
  18. Node node4 = new Node(4);
  19. Node root = new Node(1, Arrays.asList(node3, node2, node4));
  20. System.out.println(example.maxDepth(root));
  21. }
  22. public int maxDepth(Node root) {
  23. if (root == null) {
  24. return 0;
  25. }
  26. int maxDepth = 0;
  27. List<Node> children = root.children;
  28. if (children != null) {
  29. for (Node child : children) {
  30. int childDepth = maxDepth(child);
  31. maxDepth = Math.max(maxDepth, childDepth);
  32. }
  33. }
  34. return maxDepth + 1;
  35. }
  36. }
  37. class Node {
  38. public int val;
  39. public List<Node> children;
  40. public Node() {}
  41. public Node(int _val) {
  42. val = _val;
  43. }
  44. public Node(int _val, List<Node> _children) {
  45. val = _val;
  46. children = _children;
  47. }
  48. }

Review

API Architecture — Design Best Practices for REST APIs
best practices for REST APIs, summarized as follows:

  1. learn what is get/post/put/delete
  2. do not return plain text
  3. do not use verbs in URIs
  4. use plural nouns for resources
  5. return the error details in the response body
  6. pay special attention to HTTP status codes
  7. use HTTP status codes consistently
  8. do not nest resources
  9. handle trailing slashes gracefully
  10. make use of the querystring for filterring and pagination
  11. know the diffrence between 401 and 403
  12. make good use of HTTP 202
  13. use a web framework specialized in REST APIs

Tip

MySQL相关:

  1. 只要定义了字节长度,那么自增id就有上限
  2. 自增id达到上限后:在申请下一个id时,得到的值保持不变
  3. 针对上一条,应该在 InnoDB 表中主动创建自增主键。因为,表自增 id 到达上限后,再插入数据时报主键冲突错误,是更能被接受的

    Share

    如何超过大多数人

  4. 学会思考:从搜索引擎得到答案后,要学会去思考为什么是这样的,勤加思考后,很多知识点是可以串起来的

  5. 学会思考:对现在大量繁杂的信息需要有自己的判断能力,那些是对自己有帮助的。然后对其进行提炼总结,只有自己总结后的东西才是自己的。
  6. 持之以恒:计算机行业是一个需要大量学习的行业,我们不可能短时间内学习大量的知识。我们要有对自己合理的认知,在不同的阶段做不同的事,然后把它坚持下去。
  7. 提高认知
    1. 寻找一手信息
    2. 寻找高质量信息
    3. 寻找高密度信息
  8. 知识图
    1. 了解知识的缘由,知其然之后就不是死记硬背的事了
    2. 总结自己的方法。很多问题的解决是有套路可循的,比如算法有深度、广度优先等。学会总结自己的方法后,很多事情都是事半功倍。

Finish

预计完成时间:2021.11.15 ~ 2021.11.21
实际完成时间:2021.11.21
这周加了一整周的班:程序员不能只是写代码,对业务的合理性也要有自己的看法,要更加敏感才行。