本文主要是介绍[leetcode]Climbing Stairs,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
class Solution {
public:int climbStairs(int n) {// Start typing your C/C++ solution below// DO NOT write int main() functionif(n <= 2) return n;vector<int> f(n+1, 0);f[1] = 1;f[2] = 2;for(int i = 3; i <= n; i++){f[i] = f[i-1]+f[i-2];}return f[n];}
};
这篇关于[leetcode]Climbing Stairs的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!