7ms beats 99% submissions


  • 0
    P
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode(int x) { val = x; }
     * }
     */
    public class Solution {
        public int sumOfLeftLeaves(TreeNode root) {
            if(root != null)
            {if(root.left != null)
              {if(root.left.left == null && root.left.right == null)
                   return root.left.val+sumOfLeftLeaves(root.right);
               else return   sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);}
             else return sumOfLeftLeaves(root.right);}
            else return 0;
        }
    }

Log in to reply
 

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