题解 | #序列化二叉树#
序列化二叉树
http://www.nowcoder.com/practice/cf7e25aa97c04cc1a68c8f040e71fb84
String Serialize(TreeNode root) { if(root == null){ return "#" ; } return root.val+","+Serialize( root.left)+","+Serialize( root.right); } int index = 0; TreeNode Deserialize(String str) { String[] split = str.split(","); TreeNode root = null; if(!split[index] .equals("#") ){ root = new TreeNode(Integer.valueOf(split[index])); index++; root.left = Deserialize( str); root.right = Deserialize( str); }else{ index++; } return root; }