62:不同路径(un)

This commit is contained in:
huangge1199 2021-08-03 17:11:10 +08:00
parent 7deb06da05
commit 53348107c5
2 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,73 @@
//一个机器人位于一个 m x n 网格的左上角 起始点在下图中标记为 Start
//
// 机器人每次只能向下或者向右移动一步机器人试图达到网格的右下角在下图中标记为 Finish
//
// 问总共有多少条不同的路径
//
//
//
// 示例 1
//
//
//输入m = 3, n = 7
//输出28
//
// 示例 2
//
//
//输入m = 3, n = 2
//输出3
//解释
//从左上角开始总共有 3 条路径可以到达右下角
//1. 向右 -> 向下 -> 向下
//2. 向下 -> 向下 -> 向右
//3. 向下 -> 向右 -> 向下
//
//
// 示例 3
//
//
//输入m = 7, n = 3
//输出28
//
//
// 示例 4
//
//
//输入m = 3, n = 3
//输出6
//
//
//
// 提示
//
//
// 1 <= m, n <= 100
// 题目数据保证答案小于等于 2 * 109
//
// Related Topics 数学 动态规划 组合数学
// 👍 1065 👎 0
package leetcode.editor.cn;
/**
* @author huangge1199
*/
//62:不同路径
public class UniquePaths {
public static void main(String[] args) {
//测试代码
Solution solution = new UniquePaths().new Solution();
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public int uniquePaths(int m, int n) {
int max = Math.max(m, n);
return max * (max + 1) / 2;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,48 @@
<p>一个机器人位于一个 <code>m x n</code><em> </em>网格的左上角 (起始点在下图中标记为 “Start” )。</p>
<p>机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。</p>
<p>问总共有多少条不同的路径?</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/robot_maze.png" />
<pre>
<strong>输入:</strong>m = 3, n = 7
<strong>输出:</strong>28</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>m = 3, n = 2
<strong>输出:</strong>3
<strong>解释:</strong>
从左上角开始,总共有 3 条路径可以到达右下角。
1. 向右 -> 向下 -> 向下
2. 向下 -> 向下 -> 向右
3. 向下 -> 向右 -> 向下
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>m = 7, n = 3
<strong>输出:</strong>28
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>m = 3, n = 3
<strong>输出:</strong>6</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= m, n <= 100</code></li>
<li>题目数据保证答案小于等于 <code>2 * 10<sup>9</sup></code></li>
</ul>
<div><div>Related Topics</div><div><li>数学</li><li>动态规划</li><li>组合数学</li></div></div>\n<div><li>👍 1065</li><li>👎 0</li></div>