# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution(object):
def binaryTreePaths(self, root):
"""
:type root: TreeNode
:rtype: List[str]
"""
self.res=[]
if root == None:
return self.res
def dfs(root,path):
if root.left is None and root.right is None:
self.res.append(path)
if root.left:
dfs(root.left,path+'->'+str(root.left.val))
if root.right:
dfs(root.right,path+'->'+str(root.right.val))
dfs(root,str(root.val))
return self.res

leetcode Binary Tree Paths python的更多相关文章

  1. [LeetCode] Binary Tree Paths 二叉树路径

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

  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——Binary Tree Paths

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

  4. Python3解leetcode Binary Tree Paths

    问题描述: Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. E ...

  5. LeetCode Binary Tree Paths(简单题)

    题意: 给出一个二叉树,输出根到所有叶子节点的路径. 思路: 直接DFS一次,只需要判断是否到达了叶子,是就收集答案. /** * Definition for a binary tree node. ...

  6. 【LeetCode】257. Binary Tree Paths

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

  7. <LeetCode OJ> 257. Binary Tree Paths

    257. Binary Tree Paths Total Accepted: 29282 Total Submissions: 113527 Difficulty: Easy Given a bina ...

  8. [LintCode] Binary Tree Paths 二叉树路径

    Given a binary tree, return all root-to-leaf paths.Example Given the following binary tree: 1 /   \2 ...

  9. LeetCode_257. Binary Tree Paths

    257. Binary Tree Paths Easy Given a binary tree, return all root-to-leaf paths. Note: A leaf is a no ...

随机推荐

  1. WorkFlow WF如何为一个集合赋值

    今天刚刚开始学习WorkFlow.无奈WF网络上的学习资料实在太少. 刚刚学到Foreach控制流的使用,需要一个集合参数.经研究,静态赋值可以搞定.动态赋值还没. 首先添加一个List<int ...

  2. php正则表达式匹配函数

    <?php function show($var=null){ if(empty($var))  { echo 'null'; }else if(is_array($var) || is_obj ...

  3. Linux系统的简介及Linux系统的安装

    一.写在前面  本文仅仅对Linux系统进行简要的概述已经对Linux系统的安装进行简要的介绍 二.完成目标 1.Linux操作系统的基本概念 2.Linux系统的安装 三.基本概念 1.什么是操作系 ...

  4. sqlserver 2008 局域网跨服务器T-SQL操作(二)

    --判断是否开启远程操作服务,如果关闭,则开启,用完之后关闭 DECLARE @value SQL_VARIANT SELECT @value=VALUE from sys.configuration ...

  5. C语言的ELF文件格式学习

    最近的lab里面有ELF文件相关的,所以成这个几乎,学点ELF的东西. ELF,是一种文件格式.暂时,只看可执行文件的ELF文件格式. 首先,给出文件的格式的布局图: 光看这个很难理解,所以写一个小的 ...

  6. 使用VIM + Ctags

    通常在Linux或其他*Nix环境我们都使用VIM作为代码编辑工具,在纯命令终端下,它几乎是无可替代的. 它具有非常强大的扩展机制,在文字编辑方面基本上无所不能. 不过Emacs用户请不要激动,笔者还 ...

  7. sublime前端编辑器入门与个人使用经验分享

    Sublime Text(以下简称sublime)是一款很好用的代码编辑器,小巧且很灵敏,几乎可以编写大部分主流的计算机语言代码,更是堪称前端代码编辑神器. 你百度一下会发现许多sublime的安装和 ...

  8. for之Python vs C#

    class test(object): def rangetest(self): for i in range(2,0,-1): print i print i i=2 while i>0: p ...

  9. js关闭当前页面/关闭当前窗口/移动端 代码

    var userAgent = navigator.userAgent; if (userAgent.indexOf("Firefox") != -1 || userAgent.i ...

  10. Windows Azure 社区新闻综述(#68 版)

    欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话. 以下是过去一周基于您的反馈汇集在一起的内容: 文章.视频和博客文章 在 Windows Az ...