Shawngbk / Leecode

Questions of Leecode
0 stars 0 forks source link

404. Sum of Left Leaves #136

Open Shawngbk opened 7 years ago

Shawngbk commented 7 years ago

leaf的意思是没有left or right子节点

/**

public class Solution { public int sumOfLeftLeaves(TreeNode root) { if(root == null) return 0; if(root.left != null && isLeaf(root.left)) return root.left.val + sumOfLeftLeaves(root.right); else return sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right); } private boolean isLeaf(TreeNode root) { if(root.left == null && root.right == null) return true; else return false; } }

Shawngbk commented 7 years ago

Facebook