我的學習紀錄。
解題心得
因為 n 的範圍不大,先算好全部,之後直接查。
程式碼
class Solution { public: int climbStairs(int n) { int step[46] = {0, 1, 2}; for(int i=3; i<=45; i++) { step[i] = step[i-1] + step[i-2]; } return step[n]; } };
沒有留言:
張貼留言