//looking for nth element in a fibonacci-like sequence
//solution include recursion, dp and iteration.
class Solution {
public:
int climbStairs(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int s0=1;
int s1=1;
//int temp;
while(--n>0){
int temp=s0+s1;
s0=s1;
s1=temp;
}
return s1;
}
};
Leetcode: Climbing stairs

最新推荐文章于 2020-06-13 21:54:39 发布