【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 1 or 2 steps. In how many distinct ways can you climb to the top?
int climbStairs(int n) { //Runtime:0ms
int a=,b=;
if(n==)return a;
if(n==)return b;
int c=;
for(int i=;i<=n;i++){
c=a+b;
a=b;
b=c;
}
return c;
}
int climbStairs2(int n){ ////Runtime:0ms
if(n <= )return n;
int* step = new int[n];
step[] = ;
step[] = ;
for(int i = ; i < n; i++)step[i] = step[i-] + step[i-];
return step[n-];
}
【LeetCode】70 - Climbing Stairs的更多相关文章
- 【LeetCode】70. Climbing Stairs 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 题目大意 解题方法 递归 记忆化搜索 动态规划 空间压缩DP 日期 [L ...
- 【一天一道LeetCode】#70. Climbing Stairs
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 You are ...
- 【LeetCode】070. Climbing Stairs
题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...
- Leetcode之70. Climbing Stairs Easy
Leetcode 70 Climbing Stairs Easy https://leetcode.com/problems/climbing-stairs/ You are climbing a s ...
- 【leetcode❤python】70. Climbing Stairs
#Method1:动态规划##当有n个台阶时,可供选择的走法可以分两类:###1,先跨一阶再跨完剩下n-1阶:###2,先跨2阶再跨完剩下n-2阶.###所以n阶的不同走法的数目是n-1阶和n-2阶的 ...
- 【LEETCODE】70、字符匹配1023 Camelcase Matching
最近做leetcode总感觉自己是个智障,基本很少有题能自己独立做出来,都是百度... 不过终于还是做出了一题...而且速度效率还可以 哎,加油吧,尽量锤炼自己 package y2019.Algor ...
- [leetcode DP]70. Climbing Stairs
一共有n个台阶,每次跳一个或者两个,有多少种走法,典型的Fibonacii问题 class Solution(object): def climbStairs(self, n): if n<0: ...
- 【LeetCode】70. 爬楼梯
爬楼梯 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意: 给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解 ...
- 【LeetCode】746. 使用最小花费爬楼梯
使用最小花费爬楼梯 数组的每个索引做为一个阶梯,第 i个阶梯对应着一个非负数的体力花费值 cost[i](索引从0开始). 每当你爬上一个阶梯你都要花费对应的体力花费值,然后你可以选择继续爬一个阶梯或 ...
随机推荐
- 文件夹属性中只有"常规"解决办法
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Directory\shellex\PropertySheetHandlers] [HK ...
- javascript Klass 实现
var Klass=function(Parent,props){ var Child,F,i; Child=function(){ if(Child.uber && Child.ub ...
- Linux内核系列—C语言中内嵌汇编 asm __volatile__,asm__volatile_【转】
转自:http://www.bkjia.com/Androidjc/1109412.html 在内嵌汇编中,可以将C语言表达式指定为汇编指令的操作数,而且不用去管如何将C语言表达式的值读入哪个寄存器, ...
- hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them
http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭 ...
- 第三方登录(2)Android客户瑞上第三方登录百度教程
1,在 http://developer.baidu.com/ 注册成开发者 不注册看不到开发相关的链接地址.点自己的用户名,在弹出菜单显示有 <用户中心> ,没有就是没注册. 2,找到 ...
- PHP文件上传代码和逻辑详解
文件上传的逐步完善------ [简单的上传:] <form action="upload.php" method="post" enctype= ...
- 《OD学HBase》20160820
一.案例 微博: 微博内容: 关注用户和粉丝用户: 添加或移除关注用户 查看关注用户的微博内容 微博数据存储: 响应时间 秒级 无延迟 (1)mysql分布式 (2)hbase数据库 使用HBase数 ...
- git deployment strategy
http://nicolasgallagher.com/simple-git-deployment-strategy-for-static-sites/ You can still ignore a ...
- android studio sqlite操作代码片段
SQLiteDatabase db;Cursor cur; SimpleCursorAdapter adapter; // 打开或创建数据库db = openOrCreateDatabase(DB ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...