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. 利用bootstrap-select.min.js实现bootstrap下拉列表的单选和多选

    参考文章:https://blog.csdn.net/qq_37677519/article/details/78143522

  2. /Date(1555554794000)/ 转换为日期格式

    /Date(1555554794000)/ 转换为 2019/4/18 new Date(parseInt('/Date(1555554794000)/'.substr(6, 13))).toLoca ...

  3. PHP Yii2 composer环境安装

    PHP Yii2 composer环境安装 composer 安装 任意目录执行: php -r "copy('https://install.phpcomposer.com/install ...

  4. 题解:YNOI/GZOI2019 与或和

    题目大意: 1. 求所有的子矩阵的and之和2. 求所有子矩阵的or之和 由于是位运算,那么久直接拆位,于是就变成了求全0子矩阵的个数和全1子矩阵的个数那么题目就变成了简单的单调栈问题 #includ ...

  5. django csrftoken

    CSRF(跨站请求伪造) 背景知识:浏览器在发送请求的时候,会自动带上当前域名对应的cookie内容,发送给服务端,不管这个请求是来源A网站还是其它网站,只要请求的是A网站的链接,就会带上A网站的co ...

  6. 文件上传XSS引发的安全问题

    文件上传xss,一般都是上传html文件导致存储或者反射xss 一般后缀是html,之前疏忽了,没怎么考虑文件上传xss 如果没有 验证文件内容,却验证了后缀的情况下,使用: htm后缀: 测试代码: ...

  7. 大规模使用 Apache Kafka 的20个最佳实践

    必读 | 大规模使用 Apache Kafka 的20个最佳实践 配图来源:书籍<深入理解Kafka> Apache Kafka是一款流行的分布式数据流平台,它已经广泛地被诸如New Re ...

  8. Nginx下配置SSL模块,支持https

    Http与Https的区别 HTTP:是互联网上应用最为广泛的一种网络协议,是一个客户端和服务器端请求和应答的标准(TCP),用于从WWW服务器传输超文本到本地浏览器的传输协议,它可以使浏览器更加高效 ...

  9. I2C(四)linux3.4(写代码)

    title: I2C(四)linux3.4(写代码) date: 2019/1/29 17:18:42 toc: true --- I2C(四)linux3.4(写代码) 老师的参考代码 https: ...

  10. STL仿函数functor

    一:仿函数functor介绍 尽管函数指针被广泛用于实现函数回调,但C++还提供了一个重要的实现回调函数的方法,那就是函数对象. functor,翻译成函数对象,伪函数,算符,是重载了“()”操作符的 ...