/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
int findBottomLeftValue(TreeNode* root) {
queue<TreeNode*>q;
if(root==NULL)return 0;
vector<vector<int> >m;
q.push(root);
while(!q.empty()){
int k=q.size();
vector<int>cnt;
for(int i=0;i<k;i++){
cnt.push_back(q.front()->val);
TreeNode* p=q.front();
if(p->left)q.push(p->left);
if(p->right)q.push(p->right);
q.pop();
}
m.push_back(cnt);
}
return m[m.size()-1][0];
}
};
513. 找树左下角的值
最新推荐文章于 2024-09-13 16:27:15 发布