标签:split 内存 保存 利用 rar 恢复 面试题 color div
1、题目描述:
/* public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { int index = -1; String Serialize(TreeNode root) { if (root == null) { return "#"; } else { //根,序列化左子树,序列化右子树,拼接 return root.val + "," + Serialize(root.left) + "," + Serialize(root.right); } } TreeNode Deserialize(String str) { index++; String[] strArr = str.split(","); TreeNode treeNode = null; if (index > strArr.length) { return null; } if (!strArr[index].equals("#")) { //反序列化根,反序列化左子树,反序列化右子树 treeNode = new TreeNode(Integer.parseInt(strArr[index])); treeNode.left = Deserialize(str); treeNode.right = Deserialize(str); } return treeNode; } }
标签:split 内存 保存 利用 rar 恢复 面试题 color div
原文地址:https://www.cnblogs.com/guoyu1/p/12246061.html