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. 关于文件命名,你必须要知道的(浏览器报错:net::ERR_BLOCKED_BY_CLIENT)

    坑爹的,今天在写完页面,用各个浏览器测试的时候,火狐.谷歌都是正常的,QQ浏览器出幺蛾子了,在使用兼容模式的时候页面正常,使用急速模式的时候部分页面正常,点击跳转到其他页面的时候就出错了,打开控制台一 ...

  2. HoloLens开发手记 - 使用Visual Studio Using Visual Studio

    不论你是否使用DirectX或Unity来开发全息应用,你都会使用Visual Studio 2015来进行调试和部署应用.在本部分,你将会学习以下内容: 如何通过Visual Studio将你的应用 ...

  3. Go语言标准库之JSON编解码

    Go语言标准库之JSON编解码 基本的类型 Go语言中的数据类型和JSON的数据类型的关系 bool -> JSON boolean float64 -> JSON numbers str ...

  4. Python网络编程-IO阻塞与非阻塞及多路复用

    前言 问题:普通套接字实现的服务端的缺陷 一次只能服务一个客户端!                         accept阻塞! 在没有新的套接字来之前,不能处理已经建立连接的套接字的请求 re ...

  5. ubuntu下截图工具推荐 -- [deepin-scrot]

    有时候我们需要在linux下截图来保存.如果你仅仅需要全屏截图的话其实可以直接按键盘上的PrScrn或者Press Print键盘按键来实现即可: 但是如果你需要对截图的图片进行标记.画个线画个圈加个 ...

  6. IMEI

    IMEI(International Mobile Equipment Identity)是国际移动设备身份码的缩写,国际移动装备辨识码,是由15位数字组成的"电子串号",它与每台 ...

  7. 【OSX】build AOSP 2.3.7时的build error解决

    原始的error log: ============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VE ...

  8. 安装clickhouse缺少依赖libicudata.so.50()(64bit)

    root@localhost ]# rpm -ivh clickhouse-common--.el7.x86_64.rpm 错误:依赖检测失败: libicudata.so.()(64bit) 被 c ...

  9. Linux下rsync daemon模式下的错误汇总

    一.前言:最近学习服务环境搭建,遇到了许多大大小小的问题,不过还好,经过我的一通努力终于都解决了,所以分享出来给自己留个纪念,同时也希望能帮助学习中的朋友. 二.环境:两台服务器环境相同 1 [roo ...

  10. 【PyTorch深度学习60分钟快速入门 】Part3:神经网络

      神经网络可以通过使用torch.nn包来构建. 既然你已经了解了autograd,而nn依赖于autograd来定义模型并对其求微分.一个nn.Module包含多个网络层,以及一个返回输出的方法f ...