当前位置:网站首页>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 .
边栏推荐
- Denial of service DDoS Attacks
- C语言:顺序存储结构的快速排序
- R language uses LM function to build multiple linear regression model, writes regression equation according to model coefficient, and uses conflict function to give 95% confidence interval of regressi
- R language Visual scatter diagram, geom using ggrep package_ text_ The repl function avoids overlapping labels between data points (add labels to specific areas of the visual image using the parameter
- Holes in [apue] files
- 最强分布式锁工具:Redisson
- DDoS protection with iptables
- 7. Dependency injection
- Can second uncle cure young people's spiritual internal friction?
- What if the server cannot be connected (the original server cannot find the target resource)
猜你喜欢

The domestic API management tool eolink is very easy to use, creating an efficient research and development tool

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

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

30 day question brushing plan (II)

word打字时后面的字会消失是什么原因?如何解决?

Some thoughts on.Net desktop development

对“Image Denoising Using an Improved Generative Adversarial Network with Wasserstein Distance“的理解
![[dark horse morning post] byte valuation has shrunk to $270billion;](/img/58/8d5c78d919ed60bc833ec4daa22e23.jpg)
[dark horse morning post] byte valuation has shrunk to $270billion; "Second uncle" video author responded to plagiarism; Renzeping said that the abolition of the pre-sale system of commercial housing

What is the reason why the words behind word disappear when typing? How to solve it?

Blue Bridge Training (additional interview questions) day 7
随机推荐
R语言ggplot2可视化:可视化散点图并为散点图中的数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点标签互相重叠(自定义指定字体类型font family)
Humiliation, resistance, reversal, 30 years, China should win Microsoft once
SQL每日一练(牛客新题库)——第4天:高级操作符
R language uses LM function to build linear regression model and subset function to specify subset of data set to build regression model (use floor function and length function to select the former pa
Tutorial on the principle and application of database system (062) -- MySQL exercise questions: operation questions 32-38 (6)
Customized template in wechat applet
UVA11175有向图D和E From D to E and Back题解
Uva11175 digraph D and E from D to e and back
Li Kou sword finger offer 51. reverse order pairs in the array
Tutorial on the principle and application of database system (058) -- MySQL exercise (2): single choice question
数据库系统原理与应用教程(059)—— MySQL 练习题:操作题 1-10(三)
7.依赖注入
Socket类关于TCP字符流编程的理解学习
POJ3259虫洞题解
Product Manager: job responsibility table
数据库系统原理与应用教程(062)—— MySQL 练习题:操作题 32-38(六)
比XShell更好用、更现代的终端工具!
R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间(设置conf.level参数指定置信水平、置信区间的大小)
DXF读写:标注样式组码中文说明
对“Image Denoising Using an Improved Generative Adversarial Network with Wasserstein Distance“的理解