leetcode Climbing Stairs python
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
if n <= 2:
return n
last =1
nexttolast = 1
sums = 0
for i in range(2,n+1):
sums = last+nexttolast
nexttolast = last
last = sums
return sums
leetcode Climbing Stairs python的更多相关文章
- [LeetCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- Leetcode: climbing stairs
July 28, 2015 Problem statement: You are climbing a stair case. It takes n steps to reach to the top ...
- [LeetCode] Climbing Stairs (Sequence DP)
Climbing Stairs https://oj.leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It ...
- 746. Min Cost Climbing Stairs@python
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- LeetCode——Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- LeetCode:Climbing Stairs(编程之美2.9-斐波那契数列)
题目链接 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...
- [Leetcode] climbing stairs 爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] Climbing Stairs 斐波那契数列
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] 70. Climbing Stairs 爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
随机推荐
- Android 主线程和线程之间相互发送消息
通过分析Activity源码,我们知道每个Activity都有一个Looper,所以主线程在接收Message是不需要调用Looper.prepare()和Looper.loop(),但是线程是不带L ...
- 一,入门基础—— 2. 第一个project项目
1. 欢迎界面的右边是一个项目列表,显示全部近期打开的项目,双击⭕️打开之前创建的项目. 2.右击⭕️处,选择"Add Files to DemoApp..."加入一张图片. 3. ...
- Apache经常使用配置
Apache採用IBM HTTPServer,内核为Apache/2.0.47 Server version: IBM_HTTP_Server/6.1.0.13 Apache/2.0.47 查 ...
- java生成指定范围的随机数
要生成在[min,max]之间的随机整数, import java.util.Random; public class RandomTest { public static void main(Str ...
- Csharp多态的实现(抽象类)
1.什么是抽象类 抽象类是虚拟的类,不能创建对象,用abstract修饰,在子类中用override进行重写 抽象类中可以存放抽象方法,属性,也可以存放非抽象方法,属性(这个在下面的代码可以看出来的) ...
- 2016-09-06 J2EE基础知识之不知
1.中间件.容器.Web服务器 1.1中间件 中间件是提供系统软件和应用软件之间连接的软件,以便于软件各部件之间的沟通.中间件处于操作系统和更高一级应用程序之间. J2EE提出的背景: 1)企业级应用 ...
- LintCode (9)Fizz Buzz
下面是AC代码,C++风格: class Solution { public: vector<string> fizzBuzz(int N) { vector<string> ...
- C/C++输入输出
一. cin>>当碰到空格或换行符'\n'时,输入结束 该操作符是根据后面变量的类型读取数据. 输入结束条件 :遇到Enter.Space.Tab键. 对结束符的处理 :丢弃缓冲区中使得输 ...
- leetcode 4sum python
class Solution(object): def fourSum(self, nums, target): """ :type nums: List[int] :t ...
- [poco] HttpRequest之post方法
转自 http://www.cnblogs.com/yuanxiaoping_21cn_com/archive/2012/06/10/2544032.html #import <iostream ...