solution.cpp 255 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	int climbStairs(int n)
	{
		int a = 1;
		int b = 2;
		int c = 0;
		for (int i = 3; i <= n; i++)
		{
			c = a + b;
			a = b;
			b = c;
		}
		return n == 1 ? a : (n == 2 ? b : c);
	}
};