// Serialization is the process of converting a data structure or object into a sequence of bits
// so that it can be stored in a file or memory buffer,
// or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

// Design an algorithm to serialize and deserialize a binary tree.
// There is no restriction on how your serialization/deserialization algorithm should work.
// You just need to ensure that a binary tree can be serialized to a string
// and this string can be deserialized to the original tree structure.

// For example, you may serialize the following tree

//     1
//    / \
//   2   3
//      / \
//     4   5

// as "[1,2,3,null,null,4,5]", just the same as how LeetCode OJ serializes a binary tree.
// You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.


var serializeHelper = function(root,lst) {
    if (!root) { lst.push("#"); }
    else {
        lst.push(root.val);
        serializeHelper(root.left,lst);
        serializeHelper(root.right,lst);
    }
};
var serialize = function(root) {
    var lst=[];
    serializeHelper(root,lst);
    return lst.toString();
};
var deserializeHelper = function(lst) {
    if (lst.length<1) { return null; }
    var val=lst.splice(0,1);
    if (val[0]==="#") { return null; }
    var root=new TreeNode(parseInt(val));
    root.left=deserializeHelper(lst);
    root.right=deserializeHelper(lst);
    return root;
};
var deserialize = function(data) {
    if(!data||data.length===0) { return null; }
    return deserializeHelper(data.split(","));
};

@@ -902,16 +902,70 @@
 self.%0A%0A%0A
+%0Avar serialize = function(root) %7B%0A  var results=%5B%5D;%0A  
 var seri
@@ -993,16 +993,17 @@
 n(root,l
+i
 st) %7B%0A  
@@ -1000,24 +1000,26 @@
 list) %7B%0A    
+ 
+ 
 if (!root) %7B
@@ -1018,18 +1018,27 @@
 !root) %7B
+%0A       
  l
+i
 st.push(
@@ -1042,19 +1042,27 @@
 sh(%22#%22);
+%0A     
  %7D%0A
+  
     else
@@ -1064,16 +1064,18 @@
  else %7B%0A
+  
         
@@ -1094,32 +1094,34 @@
 t.val);%0A        
+  
 serializeHelper(
@@ -1131,16 +1131,17 @@
 t.left,l
+i
 st);%0A   
@@ -1137,32 +1137,34 @@
 ,list);%0A        
+  
 serializeHelper(
@@ -1175,16 +1175,17 @@
 .right,l
+i
 st);%0A   
@@ -1189,60 +1189,15 @@
     
-%7D%0A%7D;%0Avar serialize = function(root) %7B%0A    var lst=%5B%5D
+  %7D%0A  %7D
 ;%0A  
@@ -1219,19 +1219,23 @@
 er(root,
-lst
+results
 );%0A    r
@@ -1240,19 +1240,23 @@
  return 
-lst
+results
 .toStrin
@@ -1259,24 +1259,123 @@
 tring();%0A%7D;%0A
+%0A%0Avar deserialize = function(data) %7B%0A    if(!data%7C%7Cdata.length===0) %7B%0A      return null;%0A    %7D%0A    
 var deserial
@@ -1396,22 +1396,25 @@
 nction(l
+i
 st) %7B%0A
+  
     if (
@@ -1414,16 +1414,17 @@
    if (l
+i
 st.lengt
@@ -1429,16 +1429,24 @@
 gth%3C1) %7B
+%0A       
  return 
@@ -1442,35 +1442,43 @@
     return null;
+%0A     
  %7D%0A
+  
     var val=lst.
@@ -1474,16 +1474,17 @@
 ar val=l
+i
 st.splic
@@ -1491,16 +1491,18 @@
 e(0,1);%0A
+  
     if (
@@ -1516,16 +1516,24 @@
 ==%22#%22) %7B
+%0A       
  return 
@@ -1537,23 +1537,31 @@
 rn null;
+%0A     
  %7D%0A    
+  
 var root
@@ -1590,24 +1590,26 @@
 (val));%0A    
+  
 root.left=de
@@ -1617,32 +1617,33 @@
 erializeHelper(l
+i
 st);%0A    root.ri
@@ -1631,24 +1631,26 @@
 (list);%0A    
+ 
+ 
 root.right=d
@@ -1667,21 +1667,24 @@
 Helper(l
+i
 st);%0A
+  
     retu
@@ -1696,93 +1696,12 @@
 ot;%0A
+  
 %7D;
-%0Avar deserialize = function(data) %7B%0A    if(!data%7C%7Cdata.length===0) %7B return null; %7D
 %0A   

add solution