Java Postorder Traversal


  • 0
    public String tree2str(TreeNode t) {
        if (t == null) return "";
        String res = Integer.toString(t.val);
        if (t.left == null && t.right == null) return res;
        res += "(" + tree2str(t.left) + ")";
        if (t.right != null) res += "(" + tree2str(t.right) + ")";
        return res;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.