当前位置:网站首页>2022.6.22-----leetcode. five hundred and thirteen

2022.6.22-----leetcode. five hundred and thirteen

2022-06-23 08:52:00 Lu 727

    int maxh;// Maximum height 
    int ans;
    public int findBottomLeftValue(TreeNode root) {
       maxh=0;
       ans=root.val;
       dfs(root,0);
       return ans;
    }
    // Depth-first search , Record the current height 
    void dfs(TreeNode n,int h){
        if(n==null) return;
        if(h>maxh){
            maxh=h;
            ans=n.val;
        }
        dfs(n.left,h+1);
        dfs(n.right,h+1);
    }

原网站

版权声明
本文为[Lu 727]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230831320014.html