C# Solution 145ms


  • 0
    S
    public class Solution {
        public int SumOfLeftLeaves(TreeNode root) {
            return GetSumOfLeftLeaves(root, false);
        }
        
        private int GetSumOfLeftLeaves(TreeNode root, bool isLeftLeaf){
            if(root == null){
                return 0;
            }
            if(root.left == null && root.right == null){
                return isLeftLeaf ? root.val : 0;
            }
            return GetSumOfLeftLeaves(root.left, true) + GetSumOfLeftLeaves(root.right, false);
        }
    }
    

Log in to reply
 

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