[LeetCode] Climbing Stairs
来源:互联网 发布:阿里云售后电话号码 编辑:程序博客网 时间:2024/05/22 11:43
Problem : You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
1.C++版
class Solution {public: int climbStairs(int n) { if(0 >= n){ return 0; }else if(1 == n){ return 1; }else if(2 == n){ return 2; } int result = 0,first = 1,second = 2; for(int i = 3; i <= n;++ i){ result = first + second; first = second; second = result; } return result; }};
2.Java版
public class Solution { public int climbStairs(int n) { if(0 >= n){ return 0; }else if(1 == n){ return 1; }else if(2 == n){ return 2; } int result = 0,first = 1,second = 2; for(int i = 3;i <= n;++i){ result = first + second; first = second; second = result; } return result; }}
3.Python版
class Solution: # @param n, an integer # @return an integer def climbStairs(self, n): if 0 >= n: return 0 elif 1 == n: return 1 elif 2 == n: return 2 result = 0 first = 1 second = 2 for k in range(3,n+1): result = first + second first = second second = result return result
完
0 0
- LeetCode: Climbing Stairs
- LeetCode: Climbing Stairs
- [LeetCode]Climbing Stairs
- LeetCode Climbing Stairs
- [Leetcode] Climbing Stairs
- Leetcode: Climbing stairs
- LeetCode Climbing Stairs
- [LeetCode] Climbing Stairs
- leetcode 107: Climbing Stairs
- [LeetCode] Climbing Stairs
- [LeetCode]Climbing Stairs
- [leetcode]Climbing Stairs
- LeetCode-Climbing Stairs
- [leetcode] Climbing Stairs
- LeetCode - Climbing Stairs
- LeetCode:Climbing Stairs
- Leetcode Climbing Stairs
- LeetCode | Climbing Stairs
- scp和route指令学习
- 继承应用
- 数据结构目标
- Redis源码简要分析
- 华为西安2015实习生机试题基础题--------求输入的五个数字中频率最高的,输出数字和次数
- [LeetCode] Climbing Stairs
- Ubuntu Kylin 14.04 安装配置 jdk、eclipse、tomcat 通用
- wikioi1005 生日礼物 暴力搜索
- 数据库设计中的命名规范
- three.js学习 函数使用方法散记2
- 《代码大全》学习摘要(二)基本数据类型
- typedef 函数指针的用法
- wpa_supplicant--忘记网络后,wpa自动连接规则
- service能否实现不被Kill