clean javascript solution


  • 0
    3
    var sumOfLeftLeaves = function(root) {
           return sumOfLeftLeavesHelper(root,false);
    };
    
    var sumOfLeftLeavesHelper = function(root,isleft){
        if(root==null){
            return 0;
        }
        if(root.left==null&&root.right==null&&isleft){
            return root.val;
        }
        return sumOfLeftLeavesHelper(root.left,true)+sumOfLeftLeavesHelper(root.right,false);
    };
    

Log in to reply
 

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