404. Sum of Left Leaves

    xiaoxiao2021-03-25  84

    public int sumOfLeftLeaves(TreeNode root) { if(root == null) return 0; int ans = 0; if(root.left != null) { if(root.left.left == null && root.left.right == null) ans += root.left.val; else ans += sumOfLeftLeaves(root.left); } ans += sumOfLeftLeaves(root.right); return ans; }
    转载请注明原文地址: https://ju.6miu.com/read-25564.html

    最新回复(0)