【数组】Unique Paths
题目:
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的更多相关文章
- 【数组】Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- [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 ...
- 62. Unique Paths && 63 Unique Paths II
https://leetcode.com/problems/unique-paths/ 这道题,不利用动态规划基本上规模变大会运行超时,下面自己写得这段代码,直接暴力破解,只能应付小规模的情形,当23 ...
- 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 ...
- 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 ...
- 62. Unique Paths
题目: A robot is located at the top-left corner of a m x ngrid (marked 'Start' in the diagram below). ...
- 【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 ...
- Leetcode 动态规划 Unique Paths
本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie Unique Paths Total Accepted: 17915 Total Submi ...
随机推荐
- Codeforces768B Code For 1 2017-02-21 22:17 95人阅读 评论(0) 收藏
B. Code For 1 time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- pro2
#include<iostream> double sum(int n,dounle[]) { double array[100]; foe(int i=0;i<100;i++; ...
- ASP.NET MVC验证DateTime的问题
今天碰到一个Bug,在IE8中,日期验证失效,输入正确的日期格式也会验证失败,提示:xxx必须是日期格式(the field xxx must be a date) 最终找到问题所在:jquery.v ...
- 连接池--sp_reset_connection
--当客户端使用连接池访问数据库时,客户端使用OPEN来重用数据库连接,使用CLOSE来断开数据库连接,但并不物理上新建和断开连接,因此可以提高程序运行速度并降低性能损耗. --ADO和ADO.NET ...
- bootstrap-treeview中文API 以及后台JSON数据处理
bootstrap-treeview 简要教程 bootstrap-treeview是一款效果非常酷的基于bootstrap的jQuery多级列表树插件.该jQuery插件基于Twitter Bo ...
- Android实现表单提交,webapi接收
1.服务端采用的是.net的WEBAPI接口. 2.android多文件上传. 以下为核心代码: package com.example.my.androidupload; import androi ...
- css+html+JQuery 万能弹出层,居中显示
function ShowMsg(str) {//要提示的文字 $(".payment_time_mask").remove(); $("body").appe ...
- django系列8.4--django中间件的可应用案例, 限制请求次数与时间
应用案例 1.做IP访问频率限制 某些IP访问服务器的频率过高,进行拦截, 比如每分钟不能超过20次 2.URL访问过滤 如果用户访问的是login视图,就允许请求 如果访问其他视图, 需要检测是不是 ...
- Android 的文档翻译
https://www.cnblogs.com/Xiegg/p/3428529.html -------->media codec的文档翻译
- 【OCP-12c】CUUG 071题库考试原题及答案解析(23)
23.choose the best answer View the Exhibits and examine PRODUCTS and SALES tables. You issue the fol ...