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. elasticsearch补全功能之只补全筛选后的部分数据context suggester

    官方文档https://www.elastic.co/guide/en/elasticsearch/reference/5.0/suggester-context.html 下面所有演示基于elast ...

  2. IO模型、线程模型

    五种IO模型介绍和对比 https://juejin.im/post/5bd32b84f265da0ac962e7c9 Linux 的 IO 通信 以及 Reactor 线程模型浅析 https:// ...

  3. codeforces932E Team Work

    题目链接:CF932E 由第二类斯特林数知 \[ n^m=\sum_{i=0}^nS(m,i)*i!*\dbinom{n}{i} \] \[ \begin{aligned} \sum_{i=1}^n ...

  4. 【UOJ453】【集训队作业2018】围绕着我们的圆环 线性基 DP

    题目大意 有一个 \(n\times k\) 的 01矩阵 \(C\),求有多少个 \(n\times m\) 的矩阵 \(A\) 和 \(m\times k\) 的矩阵 \(B\),满足 \(A\t ...

  5. 清北学堂4.28Day1(重大更新详见贪心例一)

    枚举 用题目中给定的检验条件判定哪些是无用的,哪些是有用 的.能使命题成立的即为其解 . 例一 一棵苹果树上有n个苹果,每个苹果长在高度为Ai的地方.小明的身高为x 他想知道他最多能摘到多少苹果 数据 ...

  6. jmeter笔记(4)--测试上传附件

    性能测试过程中有HTTP请求上传附件的场景,记录一下运用fiddler和jmeter实现jforum发表上传附件的帖子的过程. 1.fiddler录制脚本 2.打开录制的脚本,调整信息头管理器中信息 ...

  7. python: c_char_p指向的bitmap图像数据,通过c_char_Array最终赋值给PIL的Image对象

    def GetCurrentImage(self): ok, bitmap, buff_len = self.GetCurrentFrameBitmap() #调用C函数,返回位图数据的指针. bit ...

  8. (转)Java结束线程的三种方法

    背景:面试过程中问到结束线程的方法和线程池shutdown shutdownnow区别以及底层的实现,当时答的并不好. Java结束线程的三种方法 线程属于一次性消耗品,在执行完run()方法之后线程 ...

  9. 洛谷P4630 铁人两项--圆方树

    一道很好的圆方树入门题 感谢PinkRabbit巨佬的博客,讲的太好啦 首先是构建圆方树的代码,也比较好想好记 void tarjan(int u) { dfn[u] = low[u] = ++dfn ...

  10. JavaScript千分符---正则实现

    一般在JavaScript中实现千分符,是使用切割+连接一顿操作 这里尝试一下使用正则快速实现千分符 let num0 = '12' let num1 = '123' let num2 = '1234 ...