当前位置:网站首页>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?
- TS扫盲大法-基础篇
- UVA11175有向图D和E From D to E and Back题解
- Denial of service DDoS Attacks
- Half wave rectification light LED
- 数据库系统原理与应用教程(059)—— MySQL 练习题:操作题 1-10(三)
- 你真的了解esModule吗
- What if the server cannot be connected (the original server cannot find the target resource)
- 力扣 剑指 Offer 51. 数组中的逆序对
- 面经整理,助力秋招,祝你称为offer收割机
猜你喜欢

国产API管理工具Eolink太好用了,打造高效的研发利器

Org.apache.ibatis.exceptions.toomanyresultsexception

Go language - Application of stack - expression evaluation

SAP ui5 fileuploader control realizes local file upload, and trial version of cross domain access error encountered when receiving server-side response

Customized template in wechat applet

Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022

30天刷题计划(二)

不用Swagger,那我用啥?

Half wave rectification light LED

111. SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误
随机推荐
[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
UVA11175有向图D和E From D to E and Back题解
【C语言】结构体指针与结构体变量作形参的区别
[security] read rfc6749 and understand the authorization code mode under oauth2.0
C语言:优化后的归并排序
R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram and set draw_ The quantiles parameter adds a specified quantile horizontal line (for example, 50%
P1797重型运输 题解
Paddleclas classification practice record
The domestic API management tool eolink is very easy to use, creating an efficient research and development tool
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
Understanding of stack and practical application scenarios
POJ3259虫洞题解
浅谈WebSocket
Socket类关于TCP字符流编程的理解学习
Denial of service DDoS Attacks
Customized template in wechat applet
Remember to use pdfbox once to parse PDF and obtain the key data of PDF
了解BFC特性,轻松实现自适应布局
UVA1599理想路径题解
Rust from introduction to mastery 01 introduction