/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/publicclassCodec{// Encodes a tree to a single string.public String serialize(TreeNode root){
Queue<TreeNode> queue =newLinkedList<>();
queue.offer(root);
StringBuilder sb =newStringBuilder();while(!queue.isEmpty()){int n = queue.size();for(int i =0; i < n; i++){
TreeNode node = queue.poll();
sb.append(node == null ?"null": node.val).append(",");if(node != null){
queue.offer(node.left);
queue.offer(node.right);}}}return sb.substring(0, sb.length()-1);}// Decodes your encoded data to tree.public TreeNode deserialize(String data){if(data.equals("null")){return null;}
String[] element = data.split(",");
Queue<TreeNode> queue =newLinkedList<>();int index =0;
TreeNode root =newTreeNode(Integer.valueOf(element[index++]));
queue.offer(root);while(!queue.isEmpty()){int n = queue.size();for(int i =0; i < n; i++){
TreeNode node = queue.poll();
String leftString = element[index++];
String rightString = element[index++];
TreeNode left = leftString.equals("null")? null :newTreeNode(Integer.parseInt(leftString));
TreeNode right = rightString.equals("null")? null :newTreeNode(Integer.parseInt(rightString));
node.left = left;
node.right = right;if(left != null){
queue.offer(left);}if(right != null){
queue.offer(right);}}}return root;}}// Your Codec object will be instantiated and called as such:// Codec ser = new Codec();// Codec deser = new Codec();// TreeNode ans = deser.deserialize(ser.serialize(root));
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {int result =0;
public intsumNumbers(TreeNode root){helper(root,0);return result;}
public voidhelper(TreeNode root,int current){if(root == null){return;}
current = current *10+ root.val;if(root.left == null && root.right == null){
result += current;}helper(root.left, current);helper(root.right, current);}}