* Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public int sumOfLeftLeaves(TreeNode root) { int sum=0; //如果为null直接返回0 if(root==null){ return 0;...
Given a binary tree, find the leftmost value in the last row of the tree. 就是拿到最后一层的第一个元素。 这个元素是最左下角的元素,不是最左侧的元素。 如果想实现 其实也很简单 就是维护更新每一层的第一个元素。 代码解读 class Solution { public int findBottomLeftValue(TreeNode root) { if...
sum-of-left-leaves /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { private int impl(TreeNode root, boolean left) { if (root == null) { retu...