leetcode — climbing-stairs
/**
*
* Source : https://oj.leetcode.com/problems/climbing-stairs/
*
*
* 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 ClimbStairs {
/**
* 每次爬一个或者两个台阶,爬到梯子顶端有多少种方法
* 爬到最高一级,要么是从n-1爬上去,要么是从n-2爬上去
* 使用动态规划,dp[n] = dp[n-1] + dp[n-2]
*
* @param n
* @return
*/
public int climb (int n) {
if (n <= 3) {
return n;
}
int[] result = new int[]{2,3};
for (int i = 4; i < n; i++) {
int temp = result[0] + result[1];
result[0] = result[1];
result[1] = temp;
}
return result[1];
}
}
leetcode — climbing-stairs的更多相关文章
- [LeetCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- Leetcode: climbing stairs
July 28, 2015 Problem statement: You are climbing a stair case. It takes n steps to reach to the top ...
- [LeetCode] Climbing Stairs (Sequence DP)
Climbing Stairs https://oj.leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It ...
- LeetCode——Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- LeetCode:Climbing Stairs(编程之美2.9-斐波那契数列)
题目链接 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...
- [Leetcode] climbing stairs 爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] Climbing Stairs 斐波那契数列
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- leetcode Climbing Stairs python
class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int " ...
- [LeetCode] Min Cost Climbing Stairs 爬楼梯的最小损失
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- Min Cost Climbing Stairs - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Min Cost Climbing Stairs - LeetCode 注意点 注意边界条件 解法 解法一:这道题也是一道dp题.dp[i]表示爬到第i层 ...
随机推荐
- Django forms表单 select下拉框的传值
今儿继续做项目,学习了Django的forms生成前端的代码. forms.py class SignupForm(forms.Form): username = forms.CharField(va ...
- 关于根据模板生成pdf文档,差入图片和加密
import com.alibaba.fastjson.JSONObject; import com.aliyun.oss.OSSClient; import com.itextpdf.text.pd ...
- 《vue.js快跑》总结:为什么选择VUE
2019-3-31 为什么选择Vue 有这个一个需求,我们需要根据后端数据接口请求返回的数组在页面中按列表展示? 传统上我们使用jQuery的Ajax发送http请求,获取数据.判断列表数据是否存在, ...
- Python Flask学习笔记之Hello World
Python Flask学习笔记之Hello World 安装virtualenv,配置Flask开发环境 virtualenv 虚拟环境是Python解释器的一个私有副本,在这个环境中可以安装私有包 ...
- php签名认证
一.概述 开年第一篇,该篇主要讲述了接口开发中,如何安全认证.如何用php签名认证. 二.说说历史 签名认证是什么?为什么要做签名认证?签名认证哪里会用到?no.no.no.....是不是,是不是,一 ...
- MySQL--MHA与GTID
##==========================================## MySQL 5.6版本引入GTID来解决主从切换时BINLOG位置点难定位的问题,MHA从0.56版本开始 ...
- 从Kubernetes到“云原生全家桶”,网易如何让业务部署提效280%?
近日,网易云轻舟微服务团队接受了CNCF的采访,分享了网易云在云原生领域尤其是Kubernetes方面的实践经验.以下为案例全文:公司:网易地点:中国杭州行业:互联网技术 挑战它的游戏业务是世界上最大 ...
- 腾讯开源 MMKV — 基于mmap的高性能通用key-value组件
一.介绍 MMKV 是基于 mmap 内存映射的 key-value 组件,底层序列化/反序列化使用 protobuf 实现,性能高,稳定性强.从 2015 年中至今,在 iOS 微信上使用已有近 3 ...
- 常见的web攻击手段
XSS:跨站脚本攻击 -典型实例为: 当用户在表达输入一段数据后,提交给服务端进行持久化.如果此用户输入的是一段脚本语言,而服务端 用户输入的数据没有经过转码.校验等就存入了数据库,在其他页面需要展示 ...
- 项目文件与 SVN 资源库同步提示错误 Attempted to lock an already-locked dir
问题描述 之前为了图方便,在eclipse中直接把三个jsp文件复制到了eclipse中我新建的一个文件夹中,把svn版本号信息也带过来了,然后我又删除了这三个jsp文件,接着先把这三个jsp复制到桌 ...