什么是 ARTS?
- 算法(Algorithm): 每周至少一道 LeetCode 算法题,加强编程训练和算法学习
- 阅读(Review): 阅读并点评至少一篇英文技术文章,提高英文水平
- 技巧 (Tip):学习至少一个技术技巧,总结、归纳日常工作中遇到的知识点
- 分享(Share):分析一篇有观点和思考的技术文章,建立影响力,输出价值观
时间周期
2022 年3月14日至3月20日
一:算法:
对称二叉树
给定一个二叉树,找出其最大深度。
二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
说明: 叶子节点是指没有子节点的节点。
示例:
给定二叉树 [3,9,20,null,null,15,7],
3
/ \
9 20
/ \
15 7
返回它的最大深度 3 。
前置知识
思路:
方法1:深度优先搜索
如果我们知道了左子树和右子树的最大深度L和R,那么该二叉树的最大深度即为:max(l,r) + 1
而左子树和右子树的最大深度游可以以同样的方式进行计算。因此我们可以用【深度优先搜索】的方法来计算二叉树的最大深度。具体而言,在计算当前二叉树的最大深度时,可以先递归计算出其左子树和右子树的最大深度,然后在O(1)时间内计算出当前二叉树的最大深度。递归在访问到空节点时退出
Python实现及其拓展资料
class Solution:
def maxDepth(self, root):
if root is None:
return 0
else:
leftHeight = self.maxDepth(root.left)
rightHeight = self.maxDepth(root.right)
return max(leftHeight, rightHeight) + 1
Java 实现及其拓展资料
class Solution {
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
} else {
int leftHeight = maxDepth(root.left);
int rightHeight = maxDepth(root.right);
return Math.max(leftHeight,rightHeight) + 1;
}
}
}
Go实现及其拓展资料
func maxDepth(root *TreeNode) int {
if root == nil {
return 0
}
return max(maxDepth(root.left), maxDepth(root.right)) + 1
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
方法2: 广度优先搜索
广度优先搜索的队列里放的是【当前层的所有节点】。每次拓展下一层的时候,不同于广度优先搜索的每次只从队列里拿出一个节点,我们需要将队列里的所有节点都拿来进行拓展,最后使用一个变量ans来维护拓展的次数,该二叉树的最大深度即为ans
JavaScript 实现及其拓展资料
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var maxDepth = function(root) {
if (!root) {
return 0
}
if (!root.left && !root.right) {
return 1
}
let cur = root
let queue = [root, null]
let depth = 1
while ((cur = queue.shift()) !== undefined) {
if (cur === null) {
if (queue.length === 0) {
return depth
}
depth++
queue.push(null)
continue
}
const l = cur.left
const r = cur.right
if (l) {
queue.push(l)
}
if (r) {
queue.push(r)
}
}
return depth
};
Java 实现及其拓展资料
class Solution {
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}
Queue<TreeNode> queue = new LinkedList<TreeNode>();
queue.offer(root);
int ans = 0;
while (!queue.isEmpty()) {
int size = queue.size();
while (size > 0) {
TreeNode node = queue.poll();
if (node.left != null) {
queue.offer(node.left);
}
if (node.right != null) {
queue.offer(node.right);
}
size--;
}
ans++;
}
return ans;
}
}
Go实现及其拓展资料
func maxDepth(root *TreeNode) int {
if root == nil {
return 0
}
queue := []*TreeNode()
queue = append(queue, root)
ans := 0
for len(queue) > 0 {
sz := len(queue)
for sz > 0 {
node := queue[0]
queue = queue[1:]
if node.left != nil {
queue = append(queue, node.left)
}
if node.right != nil {
quue = append(queue, node.right)
}
sz--
}
ans++
}
return ans
}
二:阅读,英文技术文章
Which MacBook Should You Buy?
https://www.wired.com/story/which-macbook-should-you-buy/
我的总结:
- 使用了很好的金字塔原则进行书写
- 写的通俗易懂,我一个非英语母语的都能看懂,很好
三:技巧
How to be a 10X software engineer
https://medium.com/@_michaellin/how-to-be-a-10x-engineer-fdac2a5a1bd5
我的总结:
- 没有充分的调查可用的工具
- 没有寻求帮助
- 没有穿传达商业价值
四:分享
你有错失工具症吗?
Fear of Missing Out:错失恐惧症,害怕自己错过什么有用的信息
如果应对这种症状?
- 梳理你的信息获取渠道:
- 获取的信息主要分为三类:
- 工作和职业发展需要的信息,这类信息需要系统化、详实化,比如来自书籍、论文、专栏等
- 个人成长相关的信息,比如英语、绘画、摄影、健身,在工作之外充实你的人生
- 个人兴趣或群体兴趣相关的信息,即能让你开心、放松,能让你和朋友聊天的信息
- 获取的信息主要分为三类:
- 与自己和解,承认你的时间和精力有限
- 根据谷歌的70-20-10原则规划自己的时间
- 70%的力量投入核心业务
- 20%的力量投入相关业务
- 10%的力量用在探索新业务上
- 思维上的断舍离
- 忽略对我们生活体验的质量没有帮助的事情,对更多的信息说“不”,就能解放出更多的时间投入到对我们更有意义的经历中去。
- 在信息筛选上,质量往往比数量更重要
网友评论