当前位置:网站首页>leetcode 70. climb stairs
leetcode 70. climb stairs
2022-06-27 16:58:00 【chenyson】
difficulty : Simple
The frequency of :88
subject :
Suppose you're climbing the stairs . need n You can reach the top of the building .
Every time you climb 1 or 2 A stair . How many different ways can you climb to the top of the building ?

** Their thinking :** Dynamic equation -
- It has nothing to do with the process , It's only about the result
- Dynamic programming is used for Multistage decision making problem ;( The relationship between the current stage and the previous stage ===》 State transition equation )
- The question of dynamic programming : Just ask the optimal solution , Don't ask for specific solutions ;
Code :
class Solution {
public int climbStairs(int n) {
// Because there is f[n], That is, the length is n+1
int f[]=new int[n+1]; // State definition ====f[n] It is defined as to n Step by step method to plant trees
f[0]=1; // There is only one way to stay still
f[1]=1; // There is only one way to get to the first step
// According to the state transfer equation ,i Only from 2 Start , Don't cross the border
for(int i=2;i<=n;i++){
// State transition equation
f[i]=f[i-1]+f[i-2];
}
return f[n];
}
}
边栏推荐
- How to improve it electronic equipment performance management
- A large number of missing anchor text
- Yyds dry inventory solution sword finger offer: a path with a certain value in the binary tree (3)
- [Niuke's questions] nowcoder claims to have remembered all Fibonacci numbers between 1 and 100000. To test him, we gave him a random number N and asked him to say the nth Fibonacci number. If the nth
- Relation and operation of ORM table
- localDateTime类型的时间(2019-11-19T15:16:17) 用oracle的时间范围查询
- Oracle概念二
- What is RPC
- [the way of programmer training] - 3 Character count statistics
- #yyds干货盘点# 解决剑指offer:二叉树中和为某一值的路径(三)
猜你喜欢

Unity shadow shadow pancaking

一个机器人位于一个 m x n 网格的左上角 。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角。问总共有多少条不同的路径?【LeetCodeHot100】

Oracle concept II

Array represents a collection of several intervals. Please merge all overlapping intervals and return a non overlapping interval array. The array must exactly cover all the intervals in the input. 【Le

d3dx9_ How to repair 33.dll? d3dx9_ What if 33.dll is lost?

Etcd可视化工具:Kstone部署(一),基于Helm快速部署

Oracle概念二

The interview lasted for half a year. Last month, I successfully got Alibaba p7offer. It was all because I chewed the latest interview questions in 2020!

About MySQL: the phenomenon and background of the problem

阿里云刘珅孜:云游戏带来的启发——端上创新
随机推荐
Realize simple three-D cube automatic rotation
d3dx9_ What if 27.dll is lost? d3dx9_ How to repair 27.dll?
C語言教師工作量管理系統
SQLite net (SQLite is used by unity, WPF and WinForm)
Handwritten promise series - all
Unity 阴影——阴影平坠(Shadow pancaking)
软件测试-测试的概念,单元测试的详细介绍,如何设计测试用例
Huawei cloud devcloud launched four new capabilities, setting two domestic firsts
C language teacher workload management system
Etcd可视化工具:Kstone部署(一),基于Helm快速部署
#yyds干货盘点#简述chromeV8引擎垃圾回收
tensorflow求解泊松方程
Oracle concept II
Construction and management practice of ByteDance buried point data flow
深耕数字化,引领云原生,服务更多开发者
【牛客刷题】NowCoder号称自己已经记住了1-100000之间所有的斐波那契数。 为了考验他,我们随便出一个数n,让他说出第n个斐波那契数。如果第n个斐波那契大于6位则只取后6位。
防火墙基础之源NAT地址转换和服务器映射web页面配置
模拟进程调度
Autodesk Navisworks 2022软件安装包下载及安装教程
localDateTime类型的时间(2019-11-19T15:16:17) 用oracle的时间范围查询