class Solution(object):
    def rob(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n=len(nums)
        if n==0:
            return 0
        if n==1:
            return nums[0]
        i=2
        maxinums=[nums[0],max(nums[0],nums[1])]
        
        while i<n:
        
            maxinums.append(max(maxinums[i-1],maxinums[i-2]+nums[i]))
            i+=1
        return maxinums[n-1]

sol=Solution()
print sol.rob(nums=[4,5,6,1])

【leetcode❤python】198. House Robber的更多相关文章

  1. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  2. 【leetcode❤python】 1. Two Sum

    #-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object):    def twoSum(self, nums, target):  ...

  3. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  4. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

  5. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...

  6. 【leetcode❤python】 168. Excel Sheet Column Title

    class Solution(object):    def convertToTitle(self, n):        """        :type n: in ...

  7. 【leetcode❤python】 7. Reverse Integer

    #-*- coding: UTF-8 -*-#2147483648#在32位操作系统中,由于是二进制,#其能最大存储的数据是1111111111111111111111111111111.#正因为此, ...

  8. 【leetcode❤python】 189. Rotate Array

    #-*- coding: UTF-8 -*-#由于题目要求不返回任何值,修改原始列表,#因此不能直接将新生成的结果赋值给nums,这样只是将变量指向新的列表,原列表并没有修改.#需要将新生成的结果赋予 ...

  9. 【leetcode❤python】 278. First Bad Version

    #-*- coding: UTF-8 -*-# The isBadVersion API is already defined for you.# @param version, an integer ...

随机推荐

  1. Java中的并发线程操作(只贴代码,内有注释)

    package com.thread1; public class LiffOff implements Runnable{ protected int countDown = 10; private ...

  2. 夺命雷公狗---DEDECMS----32dedecms电影网评价星星功能的实现

    我们要完成的是电影网的评价功能: 我们要做这个功能前,就要让前期工作准备好,首先让鼠标移动到星星时,星星的左边都是黄色的星星右边还是灰星星. 我们打开内容页的模版看下他代码是如何组成的: 我们在这里可 ...

  3. Java魔法堂:注释和注释模板 (转)

    http://www.cnblogs.com/fsjohnhuang/p/3988883.html 一.注释   1. 注释类型 [a]. 单行注释 // 单行注释 String type = &qu ...

  4. zw版【转发·台湾nvp系列Delphi例程】HALCON FillUp2

    zw版[转发·台湾nvp系列Delphi例程]HALCON FillUp2 procedure TForm1.Button1Click(Sender: TObject);var op : HOpera ...

  5. C# 时间现实问题(12小时制与24小时制)

    最近在修改项目中遇到时间问题,12小时制与24小时制的问题,想再次跟各位同仁提个醒. yyyy-MM-dd HH:mm:ss------大写的HH为24小时制 yyyy-MM-dd hh:mm:ss- ...

  6. (一)MapReduce篇之InputFormat,InputSplit,RecordReader(转)

    平时我们写MapReduce程序的时候,在设置输入格式的时候,总会调用形如job.setInputFormatClass(KeyValueTextInputFormat.class);来保证输入文件按 ...

  7. Selenium 新手入门(C#)1. 用vs运行调用Selenium打开页面

    Start步骤: 1.从http://docs.seleniumhq.org/download/ 下载 C# dll 文件和 Internet Explorer Driver Server(32 或 ...

  8. HDU4288:Coder(线段树单点更新版 && 暴力版)

    Problem Description In mathematics and computer science, an algorithm describes a set of procedures ...

  9. 视频处理控件TVideoGrabber中如何混合多个视频源(2)

    在前面的<视频处理控件TVideoGrabber混合多个视频源(1)>一文中,已经对TVideoGrabber中混合视频源做了一些内容的说明,本文将继续前文: >>>TV ...

  10. android 中 listview 设置自动匹配高度

    1.布局文件 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:l ...