Esay java solution


  • 0
    H
    public class Solution {
        int sum = 0;
        public int sumNumbers(TreeNode root) {
            if (root == null)
    			return 0;
    		call(root, root.val);
    		return sum;
        }
        
        public void call(TreeNode root, int oo) {
    	    if (root.left == null && root.right == null) {
    			sum += oo;
    		}
    		if (root.left != null) {
    			call(root.left, oo * 10 + root.left.val);
    		}
    		if (root.right != null) {
    			call(root.right, oo * 10 + root.right.val);
    		}
    	}
    }

Log in to reply
 

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