题目:
Given a binary tree, find the leftmost value in the last row of the tree.
void f(TreeNode* root,int cur,vector<vector<int>>& re){
if(root !=NULL){
if(cur < re.size()){
re[cur].push_back(root->val);
} else {
re.push_back(vector<int>(1,root->val));
}
f(root->left,cur+1,re);
f(root->right,cur+1,re);
}
}
class Solution {
public:
int findBottomLeftValue(TreeNode* root) {
vector<vector<int>> re;
f(root,0,re);
return re[re.size()-1][0];
}
};