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.

Show Tags
 

SOLUTION 1:

使用DP解决之。很简单。某一个cell有2种可能到达,从上面来,以及从左边来,只需要把每一个cell的可能数计算好,并且把它们相加即可。

另外,在第一行,第一列,以及左上角需要特别处理,因为我们上面、左边并没有cells.

 public class Solution {
public int uniquePaths(int m, int n) {
if (m <= || n <= ) {
return ;
} int[][] D = new int[m][n]; for (int i = ; i < m; i++) {
for (int j = ; j < n; j++) {
if (i == && j == ) {
D[i][j] = ;
} else if (i == ) {
D[i][j] = D[i][j - ];
} else if (j == ) {
D[i][j] = D[i - ][j];
} else {
D[i][j] = D[i - ][j] + D[i][j - ];
}
}
} return D[m - ][n - ];
}
}

LeetCode: Unique Paths 解题报告的更多相关文章

  1. 【LeetCode】62. Unique Paths 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...

  2. LeetCode: Unique Paths II 解题报告

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

  3. LeetCode: Combination Sum 解题报告

    Combination Sum Combination Sum Total Accepted: 25850 Total Submissions: 96391 My Submissions Questi ...

  4. 【LeetCode】576. Out of Boundary Paths 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 状态搜索 记忆化搜索 相似题目 参考资料 ...

  5. [leetcode]Unique Paths II @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths-ii/ 题意: Follow up for "Unique Paths": N ...

  6. [leetcode]Unique Paths @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths/ 题意: A robot is located at the top-left corner of ...

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

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

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

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

随机推荐

  1. UITextView

    一.由于IOS中的UITextField不支持文本换行,在需要换行的时候.我们可以用UITextView来解决这一问题.   二.创建步骤 1.初始化并设置位置和大小 UITextView *text ...

  2. 【原创】-- uboot,kennel,fs,rootfs 编译制作

    环境:ubuntu14.04  内核版本 linux 3.13.0   OK6410 内核编译环境   linux 3.0.1 uboot版本    1.1.6   交叉编译工具链   arm-lin ...

  3. 0001-Weekly Meeting on 13th and 20th March, 2015

    13th March, 2015 (1) Nearest Neighbors Using Compact Sparse Coding  ->appearing in ICML2014       ...

  4. react纯前端不依赖于打包工具的代码

    ####react最基础的语法和不依赖环境的纯前端免编译代码 参照:http://www.ruanyifeng.com/blog/2015/03/react.html 注意事项:1.必须放倒服务器上, ...

  5. [游戏学习24] MFC 各种绘图 字体学习

    >_<:这里包含字体设置及各种绘图,只要稍微看一下代码就能理解,这里不多介绍 >_<:Hello.h #include<afxwin.h> class CMyApp ...

  6. win系统下nodejs安装及环境配置

    第一步:下载安装文件下载nodejs,官网:http://nodejs.org/download/,我这里下载的是node-v0.10.28-x86.msi,如下图: 第二步:安装nodejs下载完成 ...

  7. crossplatform---Node.js Applications with VS Code

    Node.js is a platform for building fast and scalable server applications using JavaScript. Node.js i ...

  8. paip.关于动画特效原理 html js 框架总结

    paip.关于动画特效原理 html js 框架总结 1. 动画框架的来源:flex,jqueryui 3 2. 特效的分类 3 2.1. Property effects 动态改变一个或多个目标对象 ...

  9. javaweb学习总结(十五)——JSP基础语法

    任何语言都有自己的语法,JAVA中有,JSP虽然是在JAVA上的一种应用,但是依然有其自己扩充的语法,而且在JSP中,所有的JAVA语句都可以使用. 一.JSP模版元素 JSP页面中的HTML内容称之 ...

  10. mysql忘记密码重置(mac)

    setp1: 苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) step2:进入终端输入:cd /usr/local/ ...