/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Codec {
    List<String> list = new ArrayList<String>();
    public void mySerialize(TreeNode root) {
        if (root == null) {
            list.add("#");
            return;
        }

        list.add(Integer.toString(root.val));
        mySerialize(root.left);
        mySerialize(root.right);
    }

    public TreeNode myDeserialize() {
        if (list.size() == 0 || list.get(0).equals("#")) {
            if (list.size() != 0) {
                list = list.subList(1, list.size());
            }

            return null;
        }

        TreeNode root = new TreeNode(Integer.parseInt(list.get(0)));
        list = list.subList(1, list.size());
        root.left = myDeserialize();
        root.right = myDeserialize();
        return root;
    }

    // Encodes a tree to a single string.
    public String serialize(TreeNode root) {
        mySerialize(root);
        return list.toString();
    }

    // Decodes your encoded data to tree.
    public TreeNode deserialize(String data) {
        return myDeserialize();
    }
}

// Your Codec object will be instantiated and called as such:
// Codec codec = new Codec();
// codec.deserialize(codec.serialize(root));

@@ -197,63 +197,15 @@
     
-List%3CString%3E list = new ArrayList%3CString%3E();%0A    public
+private
  voi
@@ -223,32 +223,51 @@
 ze(TreeNode root
+, List%3CString%3E list
 ) %7B%0A        if (
@@ -415,16 +415,22 @@
 oot.left
+, list
 );%0A     
@@ -454,16 +454,22 @@
 ot.right
+, list
 );%0A    %7D
@@ -471,29 +471,30 @@
     %7D%0A%0A    p
-ublic
+rivate
  TreeNode my
@@ -505,16 +505,39 @@
 rialize(
+LinkedList%3CString%3E list
 ) %7B%0A    
@@ -651,38 +651,17 @@
 list
- = list.subList(1, list.size()
+.remove(0
 );%0A 
@@ -795,38 +795,17 @@
 list
- = list.subList(1, list.size()
+.remove(0
 );%0A 
@@ -829,32 +829,36 @@
 = myDeserialize(
+list
 );%0A        root.
@@ -875,24 +875,28 @@
 Deserialize(
+list
 );%0A        r
@@ -997,24 +997,77 @@
 ode root) %7B%0A
+        List%3CString%3E list = new ArrayList%3CString%3E();%0A
         mySe
@@ -1078,16 +1078,22 @@
 ize(root
+, list
 );%0A     
@@ -1099,127 +1099,628 @@
     
-return list.toString();%0A    %7D%0A%0A    // Decodes your encoded data to tree.%0A    public TreeNode deserialize(String data) %7B
+%0A        StringBuilder sb = new StringBuilder();%0A        %0A        for (int i = 0; i %3C list.size(); i++) %7B%0A            sb.append(list.get(i));%0A            %0A            if (i != list.size() - 1) %7B%0A                sb.append(%22,%22);%0A            %7D%0A        %7D%0A        %0A        return sb.toString();%0A    %7D%0A%0A    // Decodes your encoded data to tree.%0A    public TreeNode deserialize(String data) %7B%0A        String%5B%5D stringArray = data.split(%22,%22);%0A        LinkedList%3CString%3E stringList = new LinkedList%3C%3E();%0A        %0A        for (int i = 0; i %3C stringArray.length; i++) %7B%0A            stringList.add(stringArray%5Bi%5D);%0A        %7D%0A        
 %0A   
@@ -1745,16 +1745,26 @@
 rialize(
+stringList
 );%0A    %7D

Update SerializeAndDeserializeBinaryTree.java