1、题目描述

2、分析

使用递归。

3、代码

 vector<string> ans;

     vector<string> binaryTreePaths(TreeNode* root) {

         if (root == NULL) return ans;
leafPath(root,"");
return ans; } void leafPath(TreeNode *root, string s)
{
if (root == NULL)
return ;
if (root->left == NULL && root->right == NULL){
string stmp = s + to_string(root->val);
ans.push_back(stmp);
return ;
} else {
string stmp = s + to_string(root->val) + "->";
leafPath(root->left, stmp);
leafPath(root->right, stmp);
} }

LeetCode题解之Binary Tree Paths的更多相关文章

  1. 【LeetCode】257. Binary Tree Paths

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

  2. 【一天一道LeetCode】#257. Binary Tree Paths

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  3. 【LeetCode】257. Binary Tree Paths 解题报告(java & python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leet ...

  4. LeetCode OJ 257. Binary Tree Paths

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

  5. LeetCode OJ:Binary Tree Paths(二叉树路径)

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

  6. Leetcode题 257. Binary Tree Paths

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

  7. leetcode 题解:Binary Tree Inorder Traversal (二叉树的中序遍历)

    题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...

  8. [LeetCode 题解]: Flatten Binary Tree to Linked List

    Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...

  9. leetcode题解:Construct Binary Tree from Preorder and Inorder Traversal (根据前序和中序遍历构造二叉树)

    题目: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume t ...

随机推荐

  1. js设计模式小结

    1 构造函数模式 var Person = function(name){ this.name = name; this.getName = function(){ console.log(this. ...

  2. 【sping揭秘】18、使用spring访问数据

    统一的数据访问异常层次体系 基于基本的jdbc封装dao层访问接口,封装不论是访问,csv文件,关系数据库(RDBMS),ladp都可以封装成一个个DAO对象来进行访问 抛出问题 可是对于我们忽略了一 ...

  3. Centos 7 Asp.net core 使用QRCoder 报“Unable to load DLL 'gdiplus'"

    环境: Centos7 .Net core 2.0 问题: 使用QRCoder 报“Unable to load DLL 'gdiplus'" 同 https://q.cnblogs.com ...

  4. C#开源项目大全

    C#开源项目大全   商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Ph ...

  5. 搜索核心原理之网页和查询的相关性——TF-IDF

    1.相关性的演进:      i.单文本词频TF(Term Frequency)           用关键词的出现的次数除以文章的总次数,做归一化处理得到TF,来屏蔽文章长度对用关键词出现次数来衡量 ...

  6. 通过GitHub和GoDaddy搭建静态个人博客

    一.创建GitHub个人主页 通过GitHub创建个人博客的好处:无广告,因为页面代码全是你自己写的:免费,不用买主机:装X:设计和编码练习. 1. 在GitHub上创建一个新的repository, ...

  7. python虚拟环境 | virtualenv 的简单使用 (图文)

    一.创建virtualenv虚拟环境 mkvirtualenv -p 版本号 虚拟名 mkvirtualenv -p python3 env_1 python3:版本号 env_1: 虚拟环境名称 创 ...

  8. Zuul过滤器

    1.Zuul过滤器生命周期Zuul大部分功能都是通过过滤器来实现的,Zuul定义了4种标准的过滤器类型,这些过滤器类型对应于请求的典型生命周期.a.pre: 这种过滤器在请求被路由之前调用.可利用这种 ...

  9. 四层和七层负载均衡的特点及常用负载均衡Nginx、Haproxy、LVS对比

    一.四层与七层负载均衡在原理上的区别 图示: 四层负载均衡与七层负载均衡在工作原理上的简单区别如下图: 概述: 1.四层负载均衡工作在OSI模型中的四层,即传输层.四层负载均衡只能根据报文中目标地址和 ...

  10. c#cookie读取写入操作

    public static void SetCookie(string cname, string value, int effective) { HttpCookie cookie = new Ht ...