【leetcode❤python】 Sum of Left Leaves
#-*- coding: UTF-8 -*-
# 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 dfs(self,root,isLeft):
if root==None:return 0
if(root.left==None and root.right==None and isLeft==True):return root.val
return self.dfs(root.left,True)+self.dfs(root.right,False)
def sumOfLeftLeaves(self, root):
return self.dfs(root,False)
【leetcode❤python】 Sum of Left Leaves的更多相关文章
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 303. Range Sum Query - Immutable
#-*- coding: UTF-8 -*- #Tags:dynamic programming,sumRange(i,j)=sum(j)-sum(i-1)class NumArray(object) ...
- 【leetcode❤python】 112. Path Sum
#-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):# def __init_ ...
- 【Leetcode 371】Sum of Two Integers
问题描述:不使用+是或-操作符进行整数的加法运算 int getSum(int a, int b); 我的思路:把整数化成二进制进行运算,注意类型是int,也就是要考虑负数.关于负数的二进制表示可见之 ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
- 【leetcode❤python】 8. String to Integer (atoi)
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...
- 【leetcode❤python】 396. Rotate Function
#-*- coding: UTF-8 -*- #超时# lenA=len(A)# maxSum=[]# count=0# while count ...
- 【leetcode❤python】 299. Bulls and Cows
#-*- coding: UTF-8 -*-class Solution(object): def getHint(self, secret, guess): " ...
随机推荐
- ssh-copy-id帮你建立信任
一.ssh-keygen -t rsa [nameA@machineA]$ ssh-keygen -t rsa Generating public/private rsa key pair. Ente ...
- jsp struts标签迭代各种数据
首先创建一个User对象 User user=new User(); user.setUserName("张三"); user.setAge(30); User user1=new ...
- Spring 复习笔记01
Spring 框架 1. core:整个Spring框架构建在Core核心模块上,它是整个框架的的基础. 2. AOP:AOP模块提供了一个轻便但功能强大强大的AOP框架,让我们可以以AOP的形式增强 ...
- C#(winform)浏览按钮
FolderBrowserDialog folderBrowser = new FolderBrowserDialog(); //folderBrowser.SelectedPa ...
- android 开发中的常见问题
Android studio 使用极光推送, 显示获取sdk版本失败 在 build.gradle(Module.app) 添加 android { sourceSets.main { ...
- View Properties [AX 2012]
View Properties [AX 2012] Other Versions This topic has not yet been rated - Rate this topic Updated ...
- memcache缓存的使用
今天在,本地测试了一个关于memcache的demo. 本地集成环境(wamp)环境如下:php 5.5.12 .Apache 2.4.9 .mysql 5.6.17 1.除了添加配置.添加php的 ...
- fragment相关
1.鸿洋大神前两年写的,从最基础的开始详解.对常用的方法都做了精炼的总结,分上下两篇 http://blog.csdn.net/lmj623565791/article/details/3797096 ...
- 凯撒加密解密(java字母移位)
1.设计思想:加密就是将字符数据转化为ASC码表中的数字,a—w之间通过加3之后再转化为字符型输出,x—z之间通过转化为ASC码表中的数字后减去23再转化为字符型输出.解密就是将字符数据转化为ASC码 ...
- Bellman-Ford 算法及其优化
Bellman-Ford 算法及其优化 转自:http://hi.baidu.com/jzlikewei/blog/item/94db7950f96f995a1038c2cd.html Bellman ...