public String serialize(TreeNode root){
  StringBuilder sb=new StringBuilder();
  buildString(root,sb);
  return sb.toString();
}

public String serialize ( TreeNode root ) { StringBuilder sb = new StringBuilder ( ) ; buildString ( root , sb ) ; return sb . toString ( ) ; }
pre - order traversal with root and a string builder .
