Construct String from Binary Tree

给一个数组, 返回有括号表示后的pre order traversing..

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public String tree2str(TreeNode t) {
        if(t == null)
            return "";
        String right = tree2str(t.right);
        String left = tree2str(t.left);
        String res = t.val+"";
        if(right.equals("") && left.equals(""))
            return res;
        else if(right.equals("")){
            return res + "(" + left + ")";
        }
        else 
            return res + "(" + left + ")" + "(" + right + ")";
    }
}