/**
* Definition for a binary tree node.
* public class TreeNode {
* public int val;
* public TreeNode left;
* public TreeNode right;
* public TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public string Tree2str(TreeNode t) {
if (t == null)
{
return "";
} string result = t.val + ""; string left = Tree2str(t.left);
string right = Tree2str(t.right); if (left == "" && right == "")
{
return result;
}
if (left == "")
{
return result + "()" + "(" + right + ")";
}
if (right == "")
{
return result + "(" + left + ")";
}
return result + "(" + left + ")" + "(" + right + ")";
}
}

https://leetcode.com/problems/construct-string-from-binary-tree/#/description

leetcode606的更多相关文章

  1. [Swift]LeetCode606. 根据二叉树创建字符串 | Construct String from Binary Tree

    You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...

  2. Leetcode606.Construct String from Binary Tree根据二叉树创建字符串

    你需要采用前序遍历的方式,将一个二叉树转换成一个由括号和整数组成的字符串. 空节点则用一对空括号 "()" 表示.而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空 ...

随机推荐

  1. 最新Mysql5.7安装教程

    可以从MSQL官网下载MySQL服务器安装软件包,我下载为版本“mysql-installer-community-5.7.3.0-m13.msi”不多说 方法/步骤   1 双击进入安装,如下图: ...

  2. vs中: 错误,未定义的标识符getline 的解决方法

    这种情况一般都是,在使用的时候没有include<string>而导致的,加上就可以正确编译通过

  3. react: redux-devTools

    import {composeWithDeTools} from 'redux-devtools-extension'; const bindMiddleware = middleware => ...

  4. Android 静默安装/后台安装& Root permission

    Android 静默安装/后台安装& Root permission 静默安装其实很简单,今天在网上找资料找半天都说的很复杂,什么需要系统安装权限.调用系统隐藏的api.需要系统环境下编译.需 ...

  5. pip国内镜像(清华大学镜像)

    网上搜到的pip国内镜像大部分是豆瓣的 http://pypi.douban.com/simple/ 但是根本不全,很多包没有 所以推荐清华大学的 https://pypi.tuna.tsinghua ...

  6. ROS中使用ABB Yumi IRB14000的一些资料汇总

    目前,ABB RobotStudio 已经更新到6.05.01了,可至官网下载. 使用ABB RobotStudio和ROS进行联合调试,请参考下文: http://blog.csdn.net/Zha ...

  7. Kivy: Building GUI and Mobile apps with Python

    Intro Python library for building gui apps (think qt, gdk,processing) build from ground up for lates ...

  8. 当导用模块与包的import与from的问题(模块与包的调用)

    当在views.py里写impor models会不会报错呢? 1.Python里面的py文件都是每一行的代码. 2.Python解释器去找一个模块的时候,只去sys.path的路径里找 3.djan ...

  9. (七)js函数一

    1.函数概念:函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块. 语法:fuction hello(){         code...     } a)手动驱动: eg: hello(); ...

  10. [EMWIN]FRAMEWIN 与 WINDOW 的使用注意

    1.对于window控件,选中这类型控件的时候直接选中对应句柄即可: WM_InvalidateWindow(hWin); WM_SelectWindow(hWin); WM_CreateTimer( ...