Easy to understand Java top 73%


  • 0
    A
    public class Solution {
        public int sumOfLeftLeaves(TreeNode root) {
            return helper(root, false);
        }
        
        public int helper(TreeNode node, boolean isLeft) {
            if (node != null) {
                if (isLeft && node.left == null && node.right == null) {
                    return node.val;
                } else {
                    return helper(node.left, true) + helper(node.right, false);
                }
            } else {
                return 0;
            }
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.