Climbing Stairs
2015-06-17 19:03
399 查看
Description:
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?
Code:
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?
Code:
int climbStairs(int n) { if (1==n) return 1; else if (2==n) return 2; else { int p = 1, q = 2, result = 0; for (int i = 3; i <= n; i++) { result = p + q; p = q; q = result; } return result; } }
相关文章推荐
- 对retain 和 assign的理解
- Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授权字符串" UserInfo=0x17426e940 {NS
- hdu 1702 ACboy needs your help again!
- 从Clarifai的估值聊聊深度学习
- UVa 10551 - Basic Remains
- [AIR] 检测移动设备运动
- youwuku和koudaitong以及weimeng差异
- iphone使用keychain来存取用户名和密码
- RHEL6.4 安装 highpoint RocketRAID 2720 阵列卡驱动
- Xcode运行出错Installation Failed Invalid argument
- linux下,使用opencv训练级联分类器opencv_traincascade
- Installation error: INSTALL_FAILED_CPU_ABI_INCOMPATIBLE
- 浅谈使用NIO,AIO的感受
- 关于:HTTP Header -> Content-Type: text/plain Cache-Control: no-cache IE浏览器弹出错误下载对话
- linux环境下使用opencv训练级联分类器traincascade
- hdoj 1022 Train Problem I
- 【ORA-00060】 deadlock detected while waiting for resource
- 记AWSome Day Shanghai 150612
- Could not reliably determine the server's fully qualified domain name?
- HDU 1337 The Drunk Jailer--(模拟题找规律)