当前位置:网站首页>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 .
边栏推荐
- C language: random number + quick sort
- How to play a data mining game entry Edition
- Rust from introduction to mastery 01 introduction
- 微信小程序中自定义模板
- SQL daily practice (Niuke new question bank) - day 4: advanced operators
- 算法---不同路径(Kotlin)
- 比XShell更好用、更现代的终端工具!
- 数据库系统原理与应用教程(062)—— MySQL 练习题:操作题 32-38(六)
- 掌握闭包,夯实基本功
- Is azvudine, a domestic oral new coronal drug, safe? Expert authority interpretation
猜你喜欢

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

对“Image Denoising Using an Improved Generative Adversarial Network with Wasserstein Distance“的理解

DXF读写:对齐尺寸标注文字居中、上方的位置计算
![[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

111. The sap ui5 fileuploader control realizes local file upload and encounters a cross domain access error when receiving the response from the server

算法---不同路径(Kotlin)

微信小程序中自定义模板

Product Manager: job responsibility table

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

No swagger, what do I use?
随机推荐
【架构】评分较高的三本微服务书籍的阅读笔记
Blue Bridge Training (additional interview questions) day 7
Rolling update strategy of deployment.
酷炫操作预热!代码实现小星球特效
SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误的试读版
How to play a data mining game entry Edition
Understanding of stack and practical application scenarios
How to check if the interface cannot be adjusted? I didn't expect that the old bird of the 10-year test was planted on this interview question
Using fail2ban to protect web servers from DDoS Attacks
C language: random number + quick sort
C语言:随机生成数+快速排序
ES6 what amazing writing methods have you used
Tutorial on the principle and application of database system (059) -- MySQL exercise questions: operation questions 1-10 (III)
Debezium series: major changes and new features of 2.0.0.beta1
C language: optimized merge sort
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
Force buckle 2354. Number of high-quality pairs
Today's sleep quality record 75 points
Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022
Poj1860 currency exchange solution