public static void main(String[] args) { TreeNode node = new TreeNode(1); node.left = new TreeNode(2); node.right = new TreeNode(3); SumRootToLeafNumbers test = new SumRootToLeafNumbers(); System.out.println(test.sumNumbers(node)); }
public TreeNode getNode(ListNode start, ListNode end) { ListNode fast = start; ListNode slow = start; if (start == end) { return null; } while (fast != end && fast.next != end) { slow = slow.next; fast = fast.next.next; } TreeNode root = new TreeNode(slow.val); root.left = getNode(start, slow); root.right = getNode(slow.next, end); return root; }