LeetCode题解之Binary Tree Paths
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的更多相关文章
- 【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
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【LeetCode】257. Binary Tree Paths 解题报告(java & python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leet ...
- LeetCode OJ 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
- LeetCode OJ:Binary Tree Paths(二叉树路径)
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
- Leetcode题 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
- leetcode 题解:Binary Tree Inorder Traversal (二叉树的中序遍历)
题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...
- [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 ...
- 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 ...
随机推荐
- Django2.1发布,Django2.1新特性
Django 2.1 现已正式发布,官方表示随着 2.1 的发布,对 2.0 系列的主流支持服务将结束,进入安全修复服务周期,直至2019年4月. 2.1新特性:https://docs.django ...
- Python3学习笔记 - day1
前言 本文不是一篇系统的从零开始学习Python的教程,如果你需要从零开始学习Python,廖雪峰的官方网站中Python教程这部分将是比较好的一种选择,如果你英语比较好,也可以在国外的一些网站上找到 ...
- cannot download, /home/azhukov/go is a GOROOT, not a GOPATH
问题详情: go环境安装好后,运行go代码也没有问题 下载govendor包的时候提示: cannot download, /home/azhukov/go is a GOROOT, not a GO ...
- linux pidstat 命令详解
pidstat 概述 pidstat是sysstat工具的一个命令,用于监控全部或指定进程的cpu.内存.线程.设备IO等系统资源的占用情况.pidstat首次运行时显示自系统启动开始的各项统计信息, ...
- PIVOT 行列相转
先介绍一下英文释义: pivot 英 ['pɪvət] 美 ['pɪvət] n. 枢轴:中心点:旋转运动 vt. 以…为中心旋转:把…置于枢轴上 vi. 在枢轴上转动:随…转移 adj. 枢轴的: ...
- vue-05-webpack安装-vue单文件启动
1, webpack是什么 1), 是一个打包工具, 比gulp, grunt更先进 2), 额外功能 项目部署上线, 清空目录等 hot module reload, 页面刷新后, 数据不变化 3) ...
- Struts的FormFile与Commons-FileUpload控件使用心得
转自: http://www.iteye.com/topic/212566 前一段时间刚来公司,看到一个项目中以前有人写的struts代码.是使用了FormFile来处理关于文件上传的模块.但是用力一 ...
- docker私有仓库-https+nginx
一.概述 使用的是registry-2.4版本,因为在这个版本开始提供了garbage-collect,能够清理掉blobs,2.1开始提供了api的删除功能,但是只是删除的index并没有释放掉磁盘 ...
- node-webkit无边框窗口用纯JS实现拖动改变大小
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...
- U3D MonoBehaviour
一.简介 MonoBehaviour是每个脚本派生类的基类,它定义了一个脚本文件从最初被加载到最终被销毁的一个完整过程. 这个过程通过对应的方法体现出来,在不同的方法完成不同的功能,我们把这些方法称为 ...