my straightforward c++, dfs

class Solution {
public:
int findBottomLeftValue(TreeNode* root) {
pair<int,int> result(root->val,1); //root!=null
dfs(root,1,result);
return result.first;
}
private:
void dfs(TreeNode* root,int height,pair<int,int>& res)
{
if(!root->left && !root->right && height>res.second)
{
res = make_pair(root->val,height);
}
if(root->left) dfs(root->left,height+1,res);
if(root->right) dfs(root->right,height+1,res);
}
};