LeetCode_Climbing Stairs
- ou are climbing a stair case. It takes n steps to reach to the top.
- Each time you can either climb or steps. In how many distinct ways can you climb to the top?
分析:类似斐波那契序列,使用动态规划的思想。定义f(n)为台阶数为n时青蛙跳到台阶顶部的方法数。那么当n>2 时f(n) = f(n-1) + f(n-2) f(1) = 1; f(2) = 2;
- class Solution {
- public:
- int climbStairs(int n) {
- // Start typing your C/C++ solution below
- // DO NOT write int main() function
- if(n <= ) return n;
- int f1 = , f2 = , res = ;
- for(int i = ; i <= n; ++i){
- res = f1 + f2;
- f1 = f2;
- f2 = res;
- }
- return res;
- }
- };
LeetCode_Climbing Stairs的更多相关文章
- [LeetCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LintCode] 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 ...
- LintCode Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- 54. Search a 2D Matrix && Climbing Stairs (Easy)
Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This m ...
- Climbing Stairs
Climbing Stairs https://leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It tak ...
- 3月3日(6) Climbing Stairs
原题 Climbing Stairs 求斐波那契数列的第N项,开始想用通项公式求解,其实一个O(n)就搞定了. class Solution { public: int climbStairs(int ...
- Cllimbing Stairs [LeetCode 70]
1- 问题描述 You are climbing a stair case. It takes n steps to reach to the top. Each time you can eithe ...
- leetCode 70.Climbing Stairs (爬楼梯) 解题思路和方法
Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you ...
随机推荐
- rsyslog Properties 属性:
rsyslog Properties 属性: 数据项 在rsyslog 是被称为 "properties". 它们可以有不同的源, 最重要的是 那些来自接收的消息,但是还有其他. ...
- 【HDOJ】1497 Simple Library Management System
链表. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXM 1001 #def ...
- BZOJ1690: [Usaco2007 Dec]奶牛的旅行
1690: [Usaco2007 Dec]奶牛的旅行 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 552 Solved: 286[Submit][St ...
- HDU4605---Magic Ball Game(主席树 好题)
题意:一颗二叉树,任意节点要么有两个孩子要么没孩子. 然后有一个球,从结点1开始往子孙结点走. 每碰到一个结点,有三种情况 如果此球重量等于该结点重量,球就停下了 如果此球重量小于该结点重量,则分别往 ...
- hadoop-2.6.0为分布式安装
hadoop-2.6.0为分布式安装 伪分布模式集群规划(单节点)------------------------------------------------------------------- ...
- appium新版本不支持findElementByName,切换到findElementByAndroidUIAutomator
appium 1.7.6 不支持findElementByName(locator) 不知道为什么? 脚本中许多这样的语句,麻烦事情多了 org.openqa.selenium.InvalidSel ...
- iOS打电话、发邮件、发短信、打开浏览器
//1.调用 自带mail [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://163@16 ...
- android学习笔记---63-PopupWindow,泡泡窗口的实现
转载http://blog.csdn.net/lidew521/article/details/8976627 PopupWindow是一个可以显示在当前Activity之上的浮动容器,PopupWi ...
- [Android] PorterDuff使用实例----实现新浪微博图片下载效果
先上效果图,如demo_sinaweibo.gif 由效果图,下半部分是简单的效果叠加,上半部分是新浪微博加载图片显示进度的效果,显示进度的半透明区域只与根据背景图的非透明区域叠加,背景图的透明区域仍 ...
- 【iOS开发-从网络上获取图片尺寸】
实际开发过程中,容易碰到从网络上获取图片尺寸的场景,比如一个UIImageView要装载从网络上获取的图片,但要先设置其frame,此时又不知道图片尺寸,就要从网络上获取尺寸了.为了最好的用户体验,一 ...