标签:
思路:广度优先搜索即可
class Solution {public:int maxDepth(TreeNode *root) {int depth = 0;if (!root)return depth;queue<TreeNode*> nodeQue;nodeQue.push(root);while (!nodeQue.empty()){depth++;int qSize = nodeQue.size();for (size_t i = 0; i < qSize; i++){if (nodeQue.front()->left)nodeQue.push(nodeQue.front()->left);if (nodeQue.front()->right)nodeQue.push(nodeQue.front()->right);nodeQue.pop();}}return depth;}};
标签:
原文地址:http://www.cnblogs.com/flyjameschen/p/f7d1f1fbb1edbecffb39ada376fa6f60.html