请实现两个函数,分别用来序列化和反序列化二叉树。
class Solution22 { String Serialize(TreeNode22 root) { StringBuffer sb = new StringBuffer(); if(root==null){ sb.append("#,"); return sb.toString(); } sb.append(root.val); sb.append(","); sb.append(Serialize(root.left)); sb.append(Serialize(root.right)); return sb.toString(); } int index=-1; TreeNode22 Deserialize(String str) { index++; String[] strArr = str.split(","); int len=strArr.length; TreeNode22 node=null; if(!strArr[index].equals("#")){ node = new TreeNode22(Integer.parseInt(strArr[index])); node.left=Deserialize(str); node.right=Deserialize(str); } return node; } }