题目链接:点击打开链接
题目大意:略。
解题思路:略。
相关企业
- 字节跳动
- 微软(Microsoft)
- 谷歌(Google)
- 彭博(Bloomberg)
- 腾讯(Tencent)
- 苹果(Apple)
- 高盛集团(Goldman Sachs)
- 亚马逊(Amazon)
AC 代码
- Java
// 解决方案(1) class Solution { public int numWays(int n) { if (n == 0) return 1; int[] dp = new int[n + 1]; dp[0] = dp[1] = 1; for (int i = 2; i <= n; i++) { dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007; } return dp[n]; } } // 解决方案(2) class Solution { public int numWays(int n) { int a = 1, b = 1, sum; for(int i = 0; i < n; i++){ sum = (a + b) % 1000000007; a = b; b = sum; } return a; } }
- C++
class Solution { public: int numWays(int n) { int a = 1, b = 1, sum; for(int i = 0; i < n; i++){ sum = (a + b) % 1000000007; a = b; b = sum; } return a; } };