class Solution {
public String tree2str(TreeNode t) {
if(t==null) return "";
String left = tree2str(t.left);
String right = tree2str(t.right);
if(left==""&&right=="") return t.val+"";
return t.val+"("+left+")"+(right==""?"":"("+right+")");
}
}
leetcode 606 Construct String from Binary Tree
最新推荐文章于 2024-09-05 11:00:53 发布