博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【LeetCode OJ】Climbing Stairs
阅读量:6937 次
发布时间:2019-06-27

本文共 450 字,大约阅读时间需要 1 分钟。

hot3.png

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?

public class Solution {    public int climbStairs(int n) {		int a = 1;		int b = 2;		if(n == 1)			return 1;		else if(n == 2)			return 2;		int sum = 0;		for(int i = 2; i < n; ++i){			sum = a + b;			a = b;			b = sum;		}		return sum;    }}

转载于:https://my.oschina.net/u/1182234/blog/277205

你可能感兴趣的文章
微服务(二)hystrix
查看>>
课堂练习-词语接龙
查看>>
别再抱怨了,国内这么多优秀的Android资源你都知道吗?
查看>>
hausaufgabe--python 20-Closure functions 2
查看>>
实体类自动化生成 vs插件
查看>>
计算机网络技术基础知识
查看>>
笔试算法题(55):快速排序实现之三路划分, 三元中值法和插入排序处理小子文件...
查看>>
day060 ajax文件上传 json补充
查看>>
SpringBoot中常见的错误
查看>>
洗洗睡了吧啊,何必在意……费口舌不热么
查看>>
D. Ilya and Escalator
查看>>
SPF Tarjan算法求无向图割点(关节点)入门题
查看>>
转:使用 PHP 直接在共享内存中存储数据集
查看>>
转 关于 D3D的 SetRenderState 以及AlphaBlend 和AlphaTest
查看>>
基于koa2操作mysql封装例子
查看>>
如何促使团队紧密协作
查看>>
线段树模板
查看>>
Object类
查看>>
CentOS装LAMP服务器(Apache2+PHP5+MySQL)
查看>>
SVN建立分支和合并代码
查看>>