剑指offer-跳台阶

题目地址:https://www.nowcoder.com/practice/8c82a5b80378478f9484d87d1c5f12a4?tpId=13&&tqId=11161&rp=1&ru=/activity/oj&qru=/ta/coding-interviews/question-ranking

此题与斐波拉契思路一模一样,DP,再采用状态压缩

 1 class Solution {
 2 public:
 3     int jumpFloor(int number) {
 4         if(number==1)return 1;
 5         if(number==2)return 2;
 6         int l1=1,l2=2;
 7         for(int i=3;i<=number;++i){
 8             int temp=l1+l2;
 9             l1=l2;
10             l2=temp;
11         }
12         return l2;
13     }
14 };

 

posted @ 2020-09-17 12:10  LifeRunningError  Views(136)  Comments(0Edit  收藏  举报