You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.2 KiB

2 years ago
/*/*******************************************************************************
** **
** Jiedi(China nanjing)Ltd. **
** **
*******************************************************************************/
/*****************************FILE INFOMATION***********************************
**
** Project : ---leetcode
** Contact : xiacaojun@qq.com
** : http://blog.csdn.net/jiedichina
** : http://study.163.com/u/xiacaojun
https://jiedi.ke.qq.com/
csdn https://edu.csdn.net/course/detail/25037
** 51cto http://edu.51cto.com/lecturer/index/user_id-100013755.html
** http://www.laoxiaketang.com
**
** ---leetcode 296249312
** : jiedi2007
** :
**
*****************************************************************************
// 算法设计与编程实践---基于leetcode的企业真题库 课程 QQ群296249312 下载代码和交流*/
/*
* @lc app=leetcode.cn id=70 lang=cpp
*
* [70]
* 11
* 22
* 33
* 45
* 1+1+1+11+1+21+2+12+22+1+1
*/
class Solution {
public:
int fab(int n){
if(n==1 || n ==0){
return 1;
}
else
{
return fab(n-2)+fab(n-1);
}
}
int climbStairs(int n) {
//return fab(n);
int sum;
int num;//num是用来产生fab
if(n==1 || n ==0){
return 1;
}
if(n==2)
return 2;
sum = 2;
long long num_1 = 1;
long long num_2 = 2;
long long temp = 0;
for(int i=2;i<n;i++){
temp = num_2;
num_2 = num_1+num_2;
num_1 = temp;
}
return num_2;
}
};