【easy】257. Binary Tree Paths 二叉树找到所有路径
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 二叉树找到所有路径的更多相关文章
- 257 Binary Tree Paths 二叉树的所有路径
给定一个二叉树,返回从根节点到叶节点的所有路径.例如,给定以下二叉树: 1 / \2 3 \ 5所有根到叶路径是:["1->2->5", " ...
- Leetcode 257 Binary Tree Paths 二叉树 DFS
找到所有根到叶子的路径 深度优先搜索(DFS), 即二叉树的先序遍历. /** * Definition for a binary tree node. * struct TreeNode { * i ...
- [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 ...
- [LeetCode] 257. Binary Tree Paths 二叉树路径
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
- <LeetCode OJ> 257. Binary Tree Paths
257. Binary Tree Paths Total Accepted: 29282 Total Submissions: 113527 Difficulty: Easy Given a bina ...
- [LintCode] Binary Tree Paths 二叉树路径
Given a binary tree, return all root-to-leaf paths.Example Given the following binary tree: 1 / \2 ...
- 【LeetCode】257. Binary Tree Paths
Binary Tree Paths Given a binary tree, return all root-to-leaf paths. For example, given the followi ...
- LeetCode 257. Binary Tree Paths (二叉树路径)
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
- (easy)LeetCode 257.Binary Tree Paths
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
随机推荐
- 我的工具:Ping工具
C# Ping工具 通过该工具可以多个地点Ping服务器以检测服务器响应速度,同时也可以测试网站的响应速度,解析时间,服务器连接时间,下载速度 工具下载地址:https://download.csdn ...
- 微信中如何做到访问app的下载链接时直接跳到默认浏览器去执行下载
在我们使用微信营销的时候,很容易碰到H5链接在微信内无法打开或在微信内无法打开app下载页的情况.通常这种情况微信会给个提示 “已停止访问该网址” ,那么导致这个情况的因素有哪些呢,主要有以下四点 1 ...
- JS 获取某个容器控件中id包含制定字符串的控件id列表
//获取某容器控件中id包含某字符串的控件id列表 //参数:容器控件.要查找的控件的id关键字 function GetIdListBySubKey(container,subIdKey) { va ...
- 【DeepLearning】深入理解dropout正则化
本文为转载,作者:Microstrong0305 来源:CSDN 原文:https://blog.csdn.net/program_developer/article/details/80737724 ...
- SPFA求最短路——Bellman-Ford算法的优化
SPFA 算法是 Bellman-Ford算法 的队列优化算法的别称,通常用于求含负权边的单源最短路径,以及判负权环.SPFA 最坏情况下复杂度和朴素 Bellman-Ford 相同,为 O(VE), ...
- Linux-ftp服务搭建
云服务器ESC 部署vsftpd服务 记一次ftp服务搭建的采坑过程,这个坑一直卡了很久时间,都给忘记了.最近由于公司项目需要部署FTP,经过各种采坑,终于把这个坑给填上了.废话不多说,开干 环境说明 ...
- LOJ#2087 国王饮水记
解:这个题一脸不可做... 比1小的怎么办啊,好像没用,扔了吧. 先看部分分,n = 2简单,我会分类讨论!n = 4简单,我会搜索!n = 10,我会剪枝! k = 1怎么办,好像选的那些越大越好啊 ...
- 构建一个maven聚合类型的横向可扩展项目
那个时候初入java这个大家庭,学习的方向很乱.毕业后,在公司磨练了一年,总想着是该交一份答卷了,可能成绩不会很好,但求及格!那么考试题目呢,我计划搭建一个横向可扩展的项目,可以在平台自扩展各种子项目 ...
- 在vue中关于element UI 中表格实现下载功能,表头添加按钮,和点击事件失效的解决办法。
因为在element 中表格是使用el-table的形式通过数据来支撑结构,所以,表格的样式没有自己写的灵活,所以有了没法添加按钮的烦恼.下面是解决的方法. 准备工作: 一.下载npm安装包两个 1. ...
- java异常和错误相关
1.挺常见的一个问题,是个error java.lang.NoClassDefFoundError: 当目前执行的类已经编译,但是找不到它的定义时 也就是说你如果编译了一个类B,在类A中调用,编译完成 ...