pre or post order with only keeping one bound(beat 98% and 95%)
the post-order:\n\n'''\n\npublic class Codec {\n\n    // Encodes a tree to a single string.\n    public String serialize(TreeNode root) {\n        if (root == n
the post-order:\n\n'''\n\npublic class Codec {\n\n    // Encodes a tree to a single string.\n    public String serialize(TreeNode root) {\n        if (root == null) {\n            return null;\n        }\n        StringBuilder sb = new StringBuilder();\n        serialize(root, sb);\n        return sb.toString();\n    }\n    \n    private void serialize(TreeNode root, StringBuilder sb) {\n        if (root == null) {\n            return;\n        }\n        serialize(root.left, sb);\n        serialize(root.right, sb);\n        sb.append(Integer.valueOf(root.val)).append(" ");\n    }\n\n    // Decodes your encoded data to tree.\n    public TreeNode deserialize(String data) {\n        if (data == null || data.length() == 0) {\n            return null;\n        }\n        String[] nodes = data.split(" ");\n        int[] index = new int[] {nodes.length - 1};\n        return deserialize(nodes, index, Integer.MIN_VALUE);\n    }\n    \n    private TreeNode deserialize(String[] nodes, int[] index, int min) {\n        if (index[0] < 0 || Integer.valueOf(nodes[index[0]]) <= min) {\n            return null;\n        }\n        TreeNode root = new TreeNode(Integer.valueOf(nodes[index[0]--]));\n        root.right = deserialize(nodes, index, root.val);\n        root.left = deserialize(nodes, index, min);\n        return root;\n    }\n}\n\n'''\n\npre-order\n\n'''\npublic class Codec {\n\n    // Encodes a tree to a single string.\n    public String serialize(TreeNode root) {\n        if (root == null) {\n            return null;\n        }\n        StringBuilder sb = new StringBuilder();\n        serialize(root, sb);\n        return sb.toString();\n    }\n    \n    private void serialize(TreeNode root, StringBuilder sb) {\n        if (root == null) {\n            return;\n        }\n        sb.append(root.val).append(" ");\n        serialize(root.left, sb);\n        serialize(root.right, sb);\n    }\n\n    // Decodes your encoded data to tree.\n    public TreeNode deserialize(String data) {\n        if (data == null || data.length() == 0) {\n            return null;\n        }\n        String[] nodes = data.split(" ");\n        int[] index = new int[] {0};\n        return deserialize(nodes, index, Integer.MAX_VALUE);\n    }\n    \n    private TreeNode deserialize(String[] nodes, int[] index, int max) {\n        if (index[0] >= nodes.length || Integer.valueOf(nodes[index[0]]) >= max) {\n            return null;\n        }\n        TreeNode root = new TreeNode(Integer.valueOf(nodes[index[0]++]));\n        root.left = deserialize(nodes, index, root.val);\n        root.right = deserialize(nodes, index, max);\n        return root;\n    }\n}\n\n'''
[]