# 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. 【递归】【3月周赛1】【Problem B】

    Problem B Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  2. 【水:最长公共子序列】【HDU1159】【Common Subsequence】

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. webapi拦截请求

    [AttributeUsage(AttributeTargets.Method)] public class WebApiSensitive : ActionFilterAttribute { pub ...

  4. JS中的Function对象

    Function是函数的原型,所有的函数都来源于Function,获得函数的方法有两种类型,分为动态函数和函数继承. 动态函数 创建一个Function语法: var func = new Funct ...

  5. Android学习之sqlite与listview

    在android系统中使用的是sqlite数据库,前面的简易登录系统已经讲述了数据库的应用.本例的重点是实现数据库与listview的绑定.demo的数据是将个人的信息绑定到listview中,并存在 ...

  6. c#操作sqlite

    一.添加选中dll引用如下图 二.下载一个sqlite建表建库工具sqlitedatabasebrowser如下图 三.使用sqlitedatabasebrowser建库建表 四.插入表数据如下图 四 ...

  7. zoj1108 FatMouse's Speed

    给你每个物体两个参数,求最长的链要求第一个参数递增,第二个参数递减,要求输出任意最长路径. 首先第一反应根据第二个参数排个序,然后不就是最长上升子序列的问题吗? O(nlogn)的复杂度,当然这样可以 ...

  8. CxImage整理(叠加字符/图像合并)

    //CxImage叠加字符 void CCxImageTestDlg::OnBnClickedButton1() { CxImage imgJPG; // 定义一个CxImage对象 imgJPG.L ...

  9. android 应用开发对大图片的处理

    一,下载 android下载大图片(例如微博长图片)会出现OOM down掉问题 解决这个问题的办法是下载图片时先得到图片的宽度和高度,如果超出规定限制则对图片进行缩放 关键参数 1. BitmapF ...

  10. 对TCP说三道四(三次握手)

    夜朦胧,人方静,无聊的人打开了无聊的电脑看到了一张无聊的图,想着想着就睡着了,梦到了人a和人b的一次聊天. 有一天,a有事情想跟b商量就问b“有时间么,想和你聊一下天”,b想了一会发现自己能抽出时间就 ...