Given a binary tree, return all root-to-leaf paths.

For example, given the following binary tree:

1
/ \
2 3
\
5
All root-to-leaf paths are:

[“1->2->5”, “1->3”]

/*** 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>&dst,TreeNode* root,string s){if(root->left==NULL&&root->right==NULL){dst.push_back(s);return ;}if(root->left)binaryTreePaths(dst,root->left,s+"->"+to_string(root->left->val));if(root->right)binaryTreePaths(dst,root->right,s+"->"+to_string(root->right->val));}vector<string> binaryTreePaths(TreeNode* root) {vector<string>ret;if(root==NULL)return ret;binaryTreePaths(ret,root,to_string(root->val));return ret;}
};

转载于:https://www.cnblogs.com/chankeh/p/6850082.html

LeetCode : Binary Tree Paths相关推荐

  1. [LeetCode] Binary Tree Paths - 二叉树基础系列题目

    目录: 1.Binary Tree Paths - 求二叉树路径 2.Same Tree - 判断二叉树相等 3.Symmetric Tree - 判断二叉树对称镜像 Binary Tree Path ...

  2. [LeetCode] Binary Tree Paths

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

  3. LeetCode刷题记录14——257. Binary Tree Paths(easy)

    LeetCode刷题记录14--257. Binary Tree Paths(easy) 目录 前言 题目 语言 思路 源码 后记 前言 数据结构感觉理论简单,实践起来很困难. 题目 给定一个二叉树, ...

  4. Binary Tree Paths leetcode

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

  5. [LeetCode] Binary Tree Level Order Traversal 二叉树层次遍历(DFS | BFS)

    目录: 1.Binary Tree Level Order Traversal - 二叉树层次遍历 BFS 2.Binary Tree Level Order Traversal II - 二叉树层次 ...

  6. CF750G New Year and Binary Tree Paths(数位dp二进制+数学)

    CF750G New Year and Binary Tree Paths description solution code description 题目链接 一颗无穷个节点的完全二叉树. 求有多少 ...

  7. Binary Tree Paths

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

  8. LeetCode OJ -- Binary Tree Paths

    http://blog.ubooksapp.com/ 标签(空格分隔): LeetCode OJ BinaryTree Given a binary tree, return all root-to- ...

  9. 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使用matplotlib可视化散点图、并在可视化图像的底部和右边添加边缘箱图(Marginal Boxplot)
  2. 微软或允许 Android 应用运行于 Windows 和 WP
  3. PHP微信开发框架LaneWeChat框架简介
  4. Deep Residual Learning for Image Recognition 笔记
  5. Docker Compose部署项目到容器-基于Tomcat和mysql的商城项目(附源码和sql下载)
  6. 多线程(6)线程同步
  7. access2003的使用
  8. 设计模式的理解的总结
  9. string 类的扩展方法
  10. RabbitMQ和Kafka的显著差异(3)
  11. sqlcheck约束表达式怎么写_creo 5.0 建模实例教程----乌比莫斯之环教程(表达式扫描特征)...
  12. dockerfile如何运行镜像内的脚本_Docker精华问答 | Docker commit如何用?
  13. 单机配置tomcat 8 集群
  14. 《数据结构题集》2.12
  15. 双甜点预测的几点总结:
  16. codeforces1438C Engineer Artem (#682 Div2)
  17. 基于pytorch的图像识别基础完整教程
  18. C# winform抽拉式菜单栏设计的一种方法
  19. openwrt 内网域名 解析错误
  20. 51单片机仿真——中断系统(2)

热门文章

  1. google的几个搜索业务
  2. Python《使用Selenium 和pyautogui 实现自动登录淘宝》
  3. matlab将矩阵分解成lu,10行代码实现矩阵的LU分解(matlab)
  4. python变量名区分大小写_python变量名要不要区分大小写
  5. leetcode - 467. 环绕字符串中唯一的子字符串
  6. Opencv--学习Opencv比较好的网址
  7. php实现中英文网站插件,php官网英文自动跳中文
  8. Spring Boot的启动器Starter详解
  9. Shell脚本基本规则
  10. STM32 - 定时器的设定 - 基础-03 - 输出波形控制 - Output compare mode