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. python实现对文件的全量、增量备份

    #!/user/bin/env python # @Time :2018/6/6 10:10 # @Author :PGIDYSQ #@File :FileBackup2.py import os i ...

  2. Tutorial 03_分布式数据库HBASE

    (一)编程实现一下内容,并用Hadoop提供的Shell命令完成相同任务: 编程实现: (1)列出HBase所有表的相关信息,例如表名; package tutorial01; import java ...

  3. Lazy 延迟加载

    问题:最近遇到一个项目遇到一个问题(很久的项目,现阶段主要维护),程序初始化的时候比较慢,最后查原因的时候发现是因为一个类的构造方法里面有些逻辑, 解决办法:希望在使用的时候再进行加载,最后想到了延迟 ...

  4. 前端知识之Ajax

    Asynchronous JavaScript and XML 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.是在不重新加载整个页面的情况下,与服务器交换数据并异步更新部分网页 ...

  5. Java单例模式的实现

    单例的实现 单例设计模式的问题 1.      线程安全问题用synchronized修饰实例化部分代码 2.      性能问题–采用懒汉式实例化 3.      指令重排序问题–用volatile ...

  6. P1536 村村通

    原题链接 https://www.luogu.org/problemnew/show/P1536 昨天刚学的并查集,今天正好练习一下,于是就找到了这个题 看起来好像很简单,尤其是你明白了思路之后,完全 ...

  7. Flask 构建微电影视频网站(六)

    会员模块实现 会员注册 class RegistForm(FlaskForm): name = StringField( label="昵称", validators=[ Data ...

  8. ELK-filebeat收集日志到Kafka,并转存ES

    https://blog.51cto.com/tryingstuff/2052271 场景需求 在有些不需要安装java环境的服务器如Nginx,php等为主的web 应用可以使用filebeat来对 ...

  9. bzoj3678 Katu Puzzle

    题目链接 题意 给定一张图,对于每条边给出一个运算符\((\&,|,\otimes)\)和一个值\(c(0 \le c \le 1)\).问能否通过给每个点赋上一个值.使得每条边通过指定的运算 ...

  10. fhq_treap 小结

    简介 \(fhq\_treap\)是一种非旋平衡树.在学习这篇文章之前,还是先学习一下普通\(treap\)吧 优点 相比于普通的\(treap\),它可以处理区间操作. 相比于\(splay\),它 ...