/**
* 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.
publicStringserialize(TreeNoderoot){return_serialize(root,"");}// Decodes your encoded data to tree.
publicTreeNodedeserialize(Stringdata){String[]arr=data.split(",");List<String>list=newLinkedList<String>(Arrays.asList(arr));return_deserialize(list);}privateString_serialize(TreeNoderoot,Stringstr){if(null==root){str+="None,";returnstr;}str+=String.valueOf(root.val)+",";str=_serialize(root.left,str);str=_serialize(root.right,str);returnstr;}privateTreeNode_deserialize(List<String>list){if(list.get(0).equals("None")){list.remove(0);returnnull;}TreeNoderoot=newTreeNode(Integer.valueOf(list.get(0)));list.remove(0);root.left=_deserialize(list);root.right=_deserialize(list);returnroot;}}// Your Codec object will be instantiated and called as such:
// Codec codec = new Codec();
// codec.deserialize(codec.serialize(root));