src/main/java/com/leetcode/tree/medium/SerializeAndDeserializeBST_449.java
public String serialize(TreeNode root) {
    Queue<TreeNode> queue = new LinkedList<>();
    queue.add(root);

    StringBuilder result = new StringBuilder();

    while (!queue.isEmpty()) {
      TreeNode node = queue.remove();
      if (node != null) {
        queue.add(node.left);
        queue.add(node.right);
      }
      result.append(",");
      result.append(node == null ? "null" : node.val);
    }
    result.deleteCharAt(0);
    return result.toString();
  }
// Encodes a tree to a single string.
Encodes a tree to a single string.
Encodes a tree to a single string .
public String serialize(TreeNode root) {
    Queue<TreeNode> queue = new LinkedList<>();
    queue.add(root);
    StringBuilder result = new StringBuilder();
    while (!queue.isEmpty()) {
      TreeNode node = queue.remove();
      if (node != null) {
        queue.add(node.left);
        queue.add(node.right);
      }
      result.append(",");
      result.append(node == null ? "null" : node.val);
    }
    result.deleteCharAt(0);
    return result.toString();
  }
public String serialize ( TreeNode root ) { Queue < TreeNode > queue = new LinkedList < > ( ) ; queue . add ( root ) ; StringBuilder result = new StringBuilder ( ) ; while ( ! queue . isEmpty ( ) ) { TreeNode node = queue . remove ( ) ; if ( node != null ) { queue . add ( node . left ) ; queue . add ( node . right ) ; } result . append ( "," ) ; result . append ( node == null ? "null" : node . val ) ; } result . deleteCharAt ( 0 ) ; return result . toString ( ) ; }
Encodes a tree to a single string.
Encodes a tree to a single string .