Java 1liner


  • 0
    M

    public class Solution {
    public String tree2str(TreeNode t) {
    return t == null? "":String.valueOf(t.val) + (t.left != null || t.right != null? ("(" + tree2str(t.left) + ")"):"") + (t.right!=null? ("(" + tree2str(t.right) + ")"):"");
    }
    }


Log in to reply
 

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