Unique Paths [LeetCode]
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?

Above is a 3 x 7 grid. How many possible unique paths are there?
Note: m and n will be at most 100.
Solution: Pretty easy, use dynamic programming, from bottom line to top line, caculate every the path num of every cell.
class Solution {
public:
int uniquePaths(int m, int n) {
if(m <= || n <= )
return ;
vector<int> nums;
for(int i = ; i < m; i ++) {
if(i == ) {
for(int j = ; j < n; j++)
nums.push_back();
} else {
for(int j = ; j < n; j ++) {
nums[j] += nums[j - ];
}
}
}
return nums[n - ];
}
};
Unique Paths [LeetCode]的更多相关文章
- Unique Paths ——LeetCode
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- Unique Paths leetcode java
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [LeetCode] Unique Paths 不同的路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- LeetCode: Unique Paths II 解题报告
Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution Fol ...
- LeetCode: Unique Paths I & II & Minimum Path Sum
Title: https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m ...
- LeetCode 62. Unique Paths(所有不同的路径)
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- 【一天一道LeetCode】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
- 【一天一道LeetCode】#62. Unique Paths
一天一道LeetCode系列 (一)题目 A robot is located at the top-left corner of a m x n grid (marked 'Start' in th ...
随机推荐
- Nodejs发送Post请求时出现socket hang up错误的解决办法
参考nodejs官网发送http post请求的方法,实现了一个模拟post提交的功能.实际使用时报socket hang up错误. 后来发现是请求头设置的问题,发送选项中需要加上headers字段 ...
- gitlab配置和搭建 ssh
(1)查看自己之前是否生成过ssh密钥: cat ~/.ssh/id_rsa.pub 如果出现一段ssh-rsa开头的,表示已经生成了,可以跳过此步骤: (2)如果之前没有生成ssh密钥,使用命令: ...
- 多线程处理sql server2008出现Transaction (Process ID) was deadlocked on lock resources with another process and has been chose问题
多线程处理sql server2008某个表中的数据时,在Update记录的时候出现了[Transaction (Process ID 146) was deadlocked on lock reso ...
- Webbrowser控件判断网页加载完毕的简单方法 (转)
摘自:http://blog.csdn.net/cometnet/article/details/5261192 一般情况下,当ReadyState属性变成READYSTATE_COMPLETE时,W ...
- pfx,cer转pem,并对通过pem文件进行签名与验签
因为PHP无法读取.pfx文件,所以可以先转换为.pem文件然后在读取里面的数据,可以读取.cer文件,为了两方面统一,就都换成.pem然后再进行加签和验签. sign.php <?php de ...
- RTMP命令亲自测试记录
手动和自动录像模块: recorder rec1 { record all manual; record_unique on; record_notify on; record_max_size 51 ...
- Linux_常用命令_02
1. 配置网络参数: (1).root登录 --> setup命令 进入到 "text mode setup utiliy" (2).运行命令"/etc/rc.d/ ...
- 64位WIN7+oracle11g+plsql安装
64位WIN7+oracle11g+plsql安装 上部转自Oracle 11g R2 for Win7旗舰版(64位)的安装步骤 1.下载Oracle 11g R2 for Windows的版本 ...
- CentOS用yum快速安装nginx
增加nginx源 vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/ ...
- Docker-创建一个mysql容器,并保存为本地镜像
查找docker hub上的镜像 [root@wls12c ~]$ docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysq ...