leetcode 每日一题
leetcode 每日一题 1022. 从根到叶的二进制数之和
class Solution { int sum = 0; public int sumRootToLeaf(TreeNode root) { f(root, 0); return sum; } private void f(TreeNode root, int i) { if(root.left == null && root.right == null){ sum += (i<<1)+root.val; return; } if(root.left != null){ f(root.left, (i<<1) + root.val); } if(root.right != null){ f(root.right, (i<<1) + root.val); } } }


浙公网安备 33010602011771号