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]的更多相关文章

  1. 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 ...

  2. 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). ...

  3. [LeetCode] Unique Paths II 不同的路径之二

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  4. [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 ...

  5. LeetCode: Unique Paths II 解题报告

    Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution  Fol ...

  6. 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  ...

  7. 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 ...

  8. 【一天一道LeetCode】#63. Unique Paths II

    一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...

  9. 【一天一道LeetCode】#62. Unique Paths

    一天一道LeetCode系列 (一)题目 A robot is located at the top-left corner of a m x n grid (marked 'Start' in th ...

随机推荐

  1. SetWindowHookEx 做消息响应

    HHOOK g_Hook = NULL; LRESULT CALLBACK CallWndProc( _In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM l ...

  2. vsftp软链接ln遇到550错误

    centos 6.3上新建了vsftp ,用于文件下载使用 ./var/ftp/pub可以匿名登陆下载 .如果想要上传则需要使用密码验证 . 登陆使用的账号是ftpclient ,路径在/home/f ...

  3. [原创]VB注册机独辟蹊径-----注册机也可以这样写

    近段时间接了个项目,是关于一个称重传感器的上位机系统,需要一机一码针对不同的客户机分别注册,第一次注册完后,下次打开后不必注册. 刚开始想用正规的注册机办法去完成,搜罗了半天,发现现在大部分的硬盘注册 ...

  4. CALayer总结(二)

    1.CATransaction 事务: UIView有两个方法,+beginAnimations:context:和+commitAnimations,和CATransaction的+begin 和+ ...

  5. 用一张图片制作skybox图片 (如何制作360全景图、立方体)

    我转发的帖子在这里 http://dong2008hong.blog.163.com/blog/static/4696882720140294039205/ 原帖不知道地址 我这里简单整理了下 去掉了 ...

  6. 使jQuqer更高效的方法

    讨论 jQuery 和 javascript 性能的文章并不罕见.然而,本文我计划总结一些速度方面的技巧和我本人的一些建议,来提升你的 jQuery 和 javascript 代码.好的代码会带来速度 ...

  7. mysql中替换行首字符

    替换行首字符,而不替换字段中其它地方指定字符. UPDATE table SET open_time = CONCAT('W', open_time) WHERE open_time REGEXP ' ...

  8. JCO事务管理

    /* * 标准对账单过账 * @account 标准对账单号 * @year 年度 */ public List<String> doAccountStatmentPost(String ...

  9. 花神的数论题(数位dp)

    规定sum[i] 为i里面含1的个数 ,求从1-N sum[i]的乘积. 数为64位内的,也就是sum[i]<=64的,这样可以dp求出1-N中含k个1的数有多少个,快速幂一下就可以了. 有个地 ...

  10. 用JS打开网页时自动更改css样式,可用于处理浏览器兼容

    代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...