{"size": 772, "ext": "js", "max_stars_repo_path": "leetcode/javascript/606.根据二叉树创建字符串.js", "max_stars_repo_name": "Heron-Wang/HeronCode", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "leetcode/javascript/606.根据二叉树创建字符串.js", "max_issues_repo_name": "Heron-Wang/HeronCode", "max_issues_repo_issues_event_min_datetime": "2021-01-26T14:53:33.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-28T04:42:10.000Z", "max_forks_repo_path": "leetcode/javascript/606.根据二叉树创建字符串.js", "max_forks_repo_name": "Heron-Wang/HeronCode", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 17.1555555556, "max_line_length": 46, "alphanum_fraction": 0.420984456}
/*
 * @lc app=leetcode.cn id=606 lang=javascript
 *
 * [606] 根据二叉树创建字符串
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} t
 * @return {string}
 */
var tree2str = function(t) {


    function pre(t){
        let ret="";
        if(t===null)return ret;
        ret += t.val;
        if(t.left!==null){
            ret += "("+ pre(t.left)+")"
            if(t.right!==null){
                ret+="("+pre(t.right)+")";
            }
        }else if(t.right!==null){
            ret+="()("+pre(t.right)+")";
        }
        return ret;

    }

    return  pre(t);


    
};
// @lc code=end

