Algorithm
lc559_N叉树的最大深度
dfs维护最大深度即可,bfs层数也可以
链接:https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/solution/n-cha-shu-de-zui-da-shen-du-by-leetcode-n7qtv/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: int maxDepth(Node* root) { if (root == nullptr) { return 0; } int maxChildDepth = 0; vector<Node *> children = root->children; for (auto child : children) { int childDepth = maxDepth(child); maxChildDepth = max(maxChildDepth, childDepth); } return maxChildDepth + 1; } };
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| class Solution { public: int maxDepth(Node* root) { if (root == nullptr) { return 0; } queue<Node *> qu; qu.push(root); int ans = 0; while (!qu.empty()) { int size = qu.size(); while (size > 0) { Node * node = qu.front(); qu.pop(); vector<Node *> children = node->children; for (auto child : children) { qu.push(child); } size--; } ans++; } return ans; } };
|
Review
【TED演讲】电子表格的发明者
发现问题,思考解决思路,设计原型,解决问题,改变世界
Tips
鸟哥的Linux私房菜–服务器架设篇目录
Share
gdb技巧积累
- 有些地址是智能指针,所以需要自己手动判断类型去对地址指定类型输出,而不是直接
*p
,否则无法输出内容
(gdb) p *(Inode*)0x140c5500
- 查看目前情况下所有的线程堆栈.
thread apply all bt