maximum-depth-of-binary-tree 1.0.0
Maximum Depth of Binary Tree
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

int maxDepth (TreeNode *root)
 

Detailed Description

Definition at line 15 of file main.cpp.

Member Function Documentation

◆ maxDepth()

int Solution::maxDepth ( TreeNode root)
inline

Definition at line 18 of file main.cpp.

19 {
20 if (!root)
21 return 0;
22 queue<pair<TreeNode*, int>> q;
23 q.push({root, 1});
24 int level = 0;
25 while (!q.empty())
26 {
27 TreeNode* t = q.front().first;
28 level = max(level, q.front().second);
29 q.pop();
30
31 if (t->left)
32 q.push({t->left, level + 1});
33 if (t->right)
34 q.push({t->right, level + 1});
35 }
36 return level;
37 }
TreeNode * left
Definition main.cpp:8
TreeNode * right
Definition main.cpp:9

References TreeNode::left, and TreeNode::right.

Referenced by main().


The documentation for this class was generated from the following file: