本文共 681 字,大约阅读时间需要 2 分钟。
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution { public: int TreeDepth(TreeNode* pRoot) { int l = 0; if (!pRoot) return 0; dequeq; q.push_back(pRoot); while(!q.empty()) { int size = q.size(); l++; while(size--) { TreeNode* p = q.front(); q.pop_front(); if(p->left) q.push_back(p->left); if(p->right) q.push_back(p->right); } } return l; }};
转载地址:http://bnklf.baihongyu.com/