LeetCode
来源:互联网 发布:软件项目沟通机制 编辑:程序博客网 时间:2024/06/07 12:17
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Note: Given n will be a positive integer.
其实就是一个斐波那契数列题,求斐波那契数列的第N项是多少。class Solution {public: int climbStairs(int n) { vector<int> ans(n, 0); ans[0] = 1; ans[1] = 2; for (int i = 2; i < n; ++i) { ans[i] = ans[i-1] + ans[i-2]; } return ans[n-1]; }};
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- java异常处理机制简要概述
- 【Java学习之路】for、while、do-while的使用
- 冒泡排序
- jQuery操作form表单
- 17暑假预热赛--SDIBTVJ1793
- LeetCode
- jQuery Ajax
- Excel基础函数操作
- codevs 2596 售货员的难题
- Swift之自定义标签栏UITabBarController (Swift项目开始的第一步)
- java编写Dijkstra单源最短路径算法
- 数据结构:点对之间最短距离--Floyd算法
- Node.js原生开发入门完全教程
- 单调队列初步