Leetcode Climbing Stairs logN 做法
来源:互联网 发布:淘宝上的男模特大全 编辑:程序博客网 时间:2024/05/29 09:59
class _2by2{private: int d00,d01,d10,d11;public: _2by2(int d00,int d01,int d10,int d11):d00(d00),d01(d01),d10(d10),d11(d11){} void operator *= (const _2by2& rhs){ int td00 = this->d00 * rhs.d00 + this->d01 * rhs.d10; int td01 = this->d00 * rhs.d01 + this->d01 * rhs.d11; int td10 = this->d10 * rhs.d00 + this->d11 * rhs.d10; int td11 = this->d10 * rhs.d01 + this->d11 * rhs.d11; this->d00 = td00; this->d10 = td10; this->d01 = td01; this->d11 = td11; } int get00(){ return d00; }};class Solution {private: _2by2 power(_2by2& multiplier, int n){ _2by2 ans(1,0,0,1); while(n){ if(n & 1){ ans *= multiplier; } multiplier *= multiplier; n = n >> 1; } return ans; }public: int climbStairs(int n) { _2by2 multiplier(1,1,1,0); return power(multiplier,n).get00(); }};
0 0
- Leetcode Climbing Stairs logN 做法
- LeetCode: Climbing Stairs
- LeetCode: Climbing Stairs
- [LeetCode]Climbing Stairs
- LeetCode Climbing Stairs
- [Leetcode] Climbing Stairs
- Leetcode: Climbing stairs
- LeetCode Climbing Stairs
- [LeetCode] Climbing Stairs
- leetcode 107: Climbing Stairs
- [LeetCode] Climbing Stairs
- [LeetCode]Climbing Stairs
- [leetcode]Climbing Stairs
- LeetCode-Climbing Stairs
- [leetcode] Climbing Stairs
- LeetCode - Climbing Stairs
- LeetCode:Climbing Stairs
- Leetcode Climbing Stairs
- iOS 检测版本更新
- 免费的SVN服务器
- MyBatis Generator 详解
- Which Java package do I need?
- java面试之集合类
- Leetcode Climbing Stairs logN 做法
- android 支付宝SDK集成
- 多文件编译、链接
- 程序员眼中的产品经理
- 设计模式导学目录
- hbase配置详解
- weblogic启动服务时不需要输入用户名和密码
- SQL Server 数据库 不允许对索引显式地使用 DROP INDEX
- 字典对象(NSDictionary 和 NSMutableDictionary)-Objective-C