-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
64 lines (58 loc) · 1.24 KB
/
main.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <queue>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
// ²ãÐò±éÀúbfs
class Solution{
public:
int maxDepth(TreeNode* root) {
if(root == NULL)
return 0;
queue<TreeNode*> que;
que.push(root);
int depth = 0;
while(!que.empty())
{
int size = que.size();
depth++;
for(int i = 0; i < size; ++i)
{
TreeNode* tmp = que.front();
que.pop();
if(tmp->left != NULL)
que.push(tmp->left);
if(tmp->right != NULL)
que.push(tmp->right);
}
}
return depth;
}
};
// µÝ¹é°æ±¾
/*
class Solution{
public:
int maxDepth(TreeNode* root) {
return root == NULL ? 0 : max(maxDepth(root->left),maxDepth(root->right)) +1;
}
};
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root == NULL)
return 0;
int left = maxDepth(root->left) + 1;
int right = maxDepth(root->right) + 1;
return max(left,right);
}
};
*/
int main()
{
return 0;
}