题目:

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.

思路:

这道题看上去有点摸不到头脑,其实细想,到达某一点路径数就等于到达它上一点和左边点的路径数之和。这样,我们就可以建立一个二维数组,进行求解即可。

/**
* @param {number} m
* @param {number} n
* @return {number}
*/
var uniquePaths = function(m, n) {
var f=[];
for(var i=0;i<m;i++){
f[i]=[];
} for(var i=0;i<n;i++){
f[0][i]=1;
} for(var i=0;i<m;i++){
f[i][0]=1;
} for(var i=1;i<m;i++){
for(var j=1;j<n;j++){
f[i][j]=f[i-1][j]+f[i][j-1];
}
}
return f[m-1][n-1];
};

【数组】Unique Paths的更多相关文章

  1. 【数组】Unique Paths II

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

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

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

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

  4. 62. Unique Paths && 63 Unique Paths II

    https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...

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

  6. Java for LeetCode 062 Unique Paths

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  7. 62. Unique Paths

    题目: A robot is located at the top-left corner of a m x ngrid (marked 'Start' in the diagram below). ...

  8. 【LeetCode练习题】Unique Paths

    Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...

  9. Leetcode 动态规划 Unique Paths

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie Unique Paths Total Accepted: 17915 Total Submi ...

随机推荐

  1. 解决RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large问题

    使用SourceTree客户端,向远程仓库推送时:RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 Request ...

  2. Google’s Project Tango is shutting down because ARCore is already here

    https://www.theverge.com/2017/12/15/16782556/project-tango-google-shutting-down-arcore-augmented-rea ...

  3. ARKit对安卓的提示 ARKit与Google Tango

    我们知道安卓是Google开发的,那么关于AR谷歌有哪些作为呢?就是开发了Google Tango,尽管Tango还未开源,但是用户可以免费使用,可是一般的安卓手机是无法运行的,它对硬件有要求,这对它 ...

  4. POJ3281 Dining 2017-02-11 23:02 44人阅读 评论(0) 收藏

    Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...

  5. [label][Apache] VirtualHost

    <VirtualHost *:80>    ServerName   localhost    DocumentRoot "D:\www"</VirtualHos ...

  6. 关于数组以及c#学习问题

    第二次作业我没注意看群通告,看到都3月8号,开始着手想用c#试着写写,才发现一些问题. a.鞠老的要求中必须原数据需要csv文件,csv文件不是太了解,网上简单查阅了一下------csv意思是逗号分 ...

  7. SQL Union 和Union All 的区别

    Union与Union All的区别 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并 ...

  8. iOS 应用隐藏状态栏

    有时候在 Storyboard 和 target 里的设定并不足以使得应用能够完全隐藏状态栏. 这时候需要到 Info.plist,添加一项:View controller-based status ...

  9. 201621123023《Java程序设计》第8周学习总结

    一.本周学习总结 二.书面作业 1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 由图可知,传入参数后调用indexOf函数来判断是否存在,会循环整个eleme ...

  10. git删除未监视的文件

    新增的文件使用git status查看会提示Untracked files,如果想要删除Untracked files,可以使用如下命令: git clean -f # 删除Untracked fil ...