当前位置:网站首页>Algorithm --- different paths (kotlin)
Algorithm --- different paths (kotlin)
2022-07-28 13:52:00 【Xiaomi technology Android research and development caoxinyu】
subject
A robot is in a m x n The top left corner of the grid ( The starting point is marked as “Start” ).
The robot can only move down or right one step at a time . The robot tries to reach the bottom right corner of the grid ( In the figure below, it is marked as “Finish” ).
Ask how many different paths there are in total ?
Example :
Input :m = 3, n = 2
Output :3
explain :
From the top left corner , All in all 3 Path to the bottom right .
- towards the right -> Down -> Down
- Down -> Down -> towards the right
- Down -> towards the right -> Down
source : Power button (LeetCode)
link :https://leetcode.cn/problems/unique-paths
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Solutions

resolvent
fun uniquePaths(m: Int, n: Int): Int {
val dp = Array(m) {
Array(n) {
0 } }
dp[0][0] = 1
for (i in 0 until m) {
for (j in 0 until n) {
if (i == 0 && j ==0) continue
val left = if (i - 1 >= 0) dp[i - 1][j] else 0
val top = if (j - 1 >= 0) dp[i][j - 1] else 0
dp[i][j] = left + top
println(" $i $j ${
dp[i][j]}")
}
}
return dp[m - 1][n - 1]
}
summary
1. The simplest in others' eyes , Up to now, I have no idea . After reading the solution to the question, I know what the idea is .
边栏推荐
- What is the reason why the words behind word disappear when typing? How to solve it?
- R language ggplot2 visualization: visualize the scatter diagram and add text labels to the data points in the scatter diagram, using geom of ggrep package_ text_ The rep function avoids overlapping da
- Holes in [apue] files
- 了解BFC特性,轻松实现自适应布局
- To build agile teams, these methods are indispensable
- R语言因子数据的表格和列联表(交叉表)生成:使用summay函数分析列表查看卡方检验结果判断两个因子变量是否独立(使用卡方检验验证独立性)
- C language: random number + quick sort
- Rust from introduction to mastery 01 introduction
- Tutorial on the principle and application of database system (058) -- MySQL exercise (2): single choice question
- vite在项目中配置路径别名
猜你喜欢

DDoS protection with iptables

Cool operation preheating! Code to achieve small planet effect

Three men "running away" from high positions in the mobile phone factory

严格模式——let和const——箭头函数——解构赋值——字符串模板symbol——Set和Map——生成器函数

Socket类关于TCP字符流编程的理解学习

Operator3-设计一个operator

使用 IPtables 进行 DDoS 保护

Denial of service DDoS Attacks

性能超群!牛津&上海AI Lab&港大&商汤&清华强强联手,提出用于引用图像分割的语言感知视觉Transformer!代码已开源...
JWT 登录认证 + Token 自动续期方案,写得太好了!
随机推荐
力扣 2354. 优质数对的数目
浅谈WebSocket
How to play a data mining game entry Edition
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize violin diagrams, set the palette parameter, and customize the border colors of violin diagrams at different l
R language ggplot2 visualization: visualize the scatter diagram and add text labels to the data points in the scatter diagram, using geom of ggrep package_ text_ The rep function avoids overlapping da
7. Dependency injection
国产API管理工具Eolink太好用了,打造高效的研发利器
你真的了解esModule吗
DOJP1520星门跳跃题解
Go language - Application of stack - expression evaluation
性能超群!牛津&上海AI Lab&港大&商汤&清华强强联手,提出用于引用图像分割的语言感知视觉Transformer!代码已开源...
用非递归的方法实现二叉树中的层遍历,先序遍历,中序遍历和后序遍历
Debezium series: major changes and new features of 2.0.0.beta1
The strongest distributed locking tool: redisson
P1797 heavy transportation problem solution
Dojnoip201708 cheese solution
解决跨越的几种方案
111. SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误
JWT 登录认证 + Token 自动续期方案,写得太好了!
掌握常见的几种排序-选择排序