【C++】【LeetCode】62. Unique Paths
来源:互联网 发布:大数据研究方向有哪些 编辑:程序博客网 时间:2024/06/15 08:44
题目
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below).
How many possible unique paths are there?
m and n will be at most 100.
思路
其实就是一个排列组合的问题,mxn的矩形,其实就是向右走m-1步,向下走n-1步。即求
代码
class Solution {public: int uniquePaths(int m, int n) { if (m == 1 || n == 1) { return 1; } if (m * n == 0) { return 0; } int downNum = m - 1 + n - 1; int upNum = min(n - 1, m - 1); long result = 1; for (int i = downNum; i > downNum - upNum; i--) { result *= i; } for (int i = upNum; i > 1; i--) { result /= i; } return result; }};
阅读全文
0 0
- 【C++】【LeetCode】62. Unique Paths
- [LeetCode] [C++] 62. Unique Paths
- [leetcode]Unique Paths(C)
- [LeetCode]62.Unique Paths
- LeetCode --- 62. Unique Paths
- LeetCode 62.Unique Paths
- [Leetcode] 62. Unique Paths
- [leetcode] 62.Unique Paths
- [leetcode] 62.Unique Paths
- leetcode 62. Unique Paths
- Leetcode 62. Unique Paths
- [leetcode] 62. Unique Paths
- 62. Unique Paths LeetCode
- [LeetCode]62. Unique Paths
- 【LeetCOde】62. Unique Paths
- [LeetCode]62. Unique Paths
- leetcode 62. Unique Paths
- LeetCode 62. Unique Paths
- Python的collections模块中的OrderedDict有序字典
- 在MATLAB中将数据输出到多个文件中
- 构造图
- Catalan数计算及应用
- spring学习day1
- 【C++】【LeetCode】62. Unique Paths
- Android 项目中ButterKnife的基本使用
- 快速排序的时间复杂度和空间复杂度
- 杭电5914-斐波那契数列思路
- 判断字符串是否没有重复字符
- 大型网站架构的技术演进
- 计蒜客 包含233的五位数
- linux网络——iptables与网关
- 台阶问题