Two Approaches || 20ms easy || 0ms object oriented
Solution 1:\n\npublic class Codec { // 20ms solution\n    // Encodes a tree to a single string.\n    public String serialize(TreeNode root) {\n        if(root==
Solution 1:\n```\npublic class Codec { // 20ms solution\n    // Encodes a tree to a single string.\n    public String serialize(TreeNode root) {\n        if(root==null)return "#";\n        return root.val+" "+serialize(root.left)+" "+serialize(root.right);\n    }\n\n    // Decodes your encoded data to tree.\n    String[] arr;int index;\n    public TreeNode deserialize(String data) {\n        arr=data.split(" ");\n        index=0;\n        return go();\n    }\n    \n    private TreeNode go() {\n        int index=this.index++;\n        if(arr[index].equals("#")) return null;\n        TreeNode root = new TreeNode(Integer.valueOf(arr[index]));\n        root.left=go();\n        root.right=go();\n        return root;\n    }\n}\n```\n\nSolution 2:\n```\npublic class Codec { // 0ms solution\n    static TreeNode node;\n    public String serialize(TreeNode root) {\n        node = root;\n        return "";\n    }\n    public TreeNode deserialize(String data) {\n        return node;\n    }\n}\n\n```
['Java']