http://blog.csdn.net/crazy1235/article/details/51474128

花样做二叉树的题……居然还是不会么……

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void binaryTreePaths(vector<string>& result,TreeNode* root,string t)
{
if(!root->left&&!root->right)
{
result.push_back(t);
return;
}
if(root->left)
binaryTreePaths(result,root->left,t+"->"+to_string(root->left->val));
if(root->right)
binaryTreePaths(result,root->right,t+"->"+to_string(root->right->val)); } vector<string> binaryTreePaths(TreeNode* root) {
vector<string> result;
if(root==NULL) return result; binaryTreePaths(result,root,to_string(root->val)); return result; }
};

【easy】257. Binary Tree Paths 二叉树找到所有路径的更多相关文章

  1. 257 Binary Tree Paths 二叉树的所有路径

    给定一个二叉树,返回从根节点到叶节点的所有路径.例如,给定以下二叉树:   1 /   \2     3 \  5所有根到叶路径是:["1->2->5", " ...

  2. Leetcode 257 Binary Tree Paths 二叉树 DFS

    找到所有根到叶子的路径 深度优先搜索(DFS), 即二叉树的先序遍历. /** * Definition for a binary tree node. * struct TreeNode { * i ...

  3. [leetcode]257. Binary Tree Paths二叉树路径

    Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example ...

  4. [LeetCode] 257. Binary Tree Paths 二叉树路径

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...

  5. &lt;LeetCode OJ&gt; 257. Binary Tree Paths

    257. Binary Tree Paths Total Accepted: 29282 Total Submissions: 113527 Difficulty: Easy Given a bina ...

  6. [LintCode] Binary Tree Paths 二叉树路径

    Given a binary tree, return all root-to-leaf paths.Example Given the following binary tree: 1 /   \2 ...

  7. 【LeetCode】257. Binary Tree Paths

    Binary Tree Paths Given a binary tree, return all root-to-leaf paths. For example, given the followi ...

  8. LeetCode 257. Binary Tree Paths (二叉树路径)

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...

  9. (easy)LeetCode 257.Binary Tree Paths

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...

随机推荐

  1. JS Arry 常用方法总结

    var arr = ["a", "b", "c", "1", "2", "3"] ...

  2. mysql 在线加索引 锁表

    mysql在线修改表结构大数据表的风险与解决办法归纳 - 王滔 - 博客园 http://www.cnblogs.com/wangtao_20/p/3504395.html MySQL 加索引 加字段 ...

  3. Linux下Nginx配置阿里云 SSL证书实现HTTPS访问

    这篇文章主要介绍了nginx配置ssl证书实现https访问的示例 1.服务器系统:Centos 2. 阿里云申请SSL证书 选择“免费版DV SSL”,点击立即购买: 下载证书 列表中找到已签发的证 ...

  4. AI佳作解读系列(四)——数据增强篇

    前言 在深度学习的应用过程中,数据的重要性不言而喻.继上篇介绍了数据合成(个人认为其在某种程度上可被看成一种数据增强方法)这个主题后,本篇聚焦于数据增强来介绍几篇杰作! (1)NanoNets : H ...

  5. vue上传图片 base64+canvas压缩图片

    这是先将图片 base64转码 在拿canvas压缩的

  6. Java 中数字和字符串拼接的问题

    注意细节 字符是char 类型,字符串是String 类型1.数字拼接char,得到的还是数字,相当于和它的ASCII编码相加(如果定义成String 会编译错误)2.数字拼接String,得到的是S ...

  7. JDK源码分析(8) StringBuffer & StringBuilder

    简介 StringBuffer与StringBuilder是两个常用的操作字符串的类.大家都知道,StringBuilder是线程不安全的,而StringBuffer是线程安全的.前者是JDK1.5加 ...

  8. python第九天

    复习内容: 文件处理 1. 操作文件的三步骤: ---打开文件:硬盘的空间被操作系统持有  |  文件对象被应用程序持有 ---操作文件:读写操作 ---释放文件:释放操作系统对硬盘空间的持有 2. ...

  9. GWAS后续分析:多基因风险评分(Polygenic Risk Score)的计算

    一.什么是多基因风险评分 传统的GWAS研究只计算单个SNP位点与表型之间的关联性,再用Bonferroni校正,通过给定的阈值,筛选出显著的SNP位点. 这样会存在两个问题,第一.Bonferron ...

  10. datable中table.row() not a funtion 解决方法

    解决办法一: 改为.DataTable({ (初始化时候) 解决办法二: 或者改为var data = myTable.api().row( this ).data();(获取值的时候)