mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 104.cpp
This commit is contained in:
parent
69f74c257b
commit
52f610aeae
24
LeetCode-CN/104.cpp
Normal file
24
LeetCode-CN/104.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
class Solution {
|
||||
public:
|
||||
int maxDepth(TreeNode* root) {
|
||||
if (!root) return 0;
|
||||
std::queue<std::pair<TreeNode*, int>> bus;
|
||||
bus.push(std::make_pair(root, 1));
|
||||
int hmax = 1;
|
||||
while (!bus.empty())
|
||||
{
|
||||
std::pair<TreeNode*,int> now = bus.front();
|
||||
hmax = std::max(hmax, now.second);
|
||||
bus.pop();
|
||||
if (now.first->left)
|
||||
{
|
||||
bus.push(std::make_pair(now.first->left, now.second + 1));
|
||||
}
|
||||
if (now.first->right)
|
||||
{
|
||||
bus.push(std::make_pair(now.first->right, now.second + 1));
|
||||
}
|
||||
}
|
||||
return hmax;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user