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 7 x 3 grid. How many possible unique paths are there?

Note: m and n will be at most 100.

Example 1:

Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Right -> Down
2. Right -> Down -> Right
3. Down -> Right -> Right

Example 2:

Input: m = 7, n = 3
Output: 28

动态规划,当前值和左边格子与上边格子的状态有关;状态仅与当前行和上一行有关,并且由于是从上往下、从左往右遍历的,可以只使用一维数组存储。

class Solution {
public int uniquePaths(int m, int n) {
int[] dp = new int[n];
dp[0] = 1;
for(int i = 0; i < m; i++){
for(int j = 1; j < n; j++){
dp[j] += dp[j-1];
}
}
return dp[n-1];
}
}

62. Unique Paths (JAVA)的更多相关文章

  1. leetcode 62. Unique Paths 、63. Unique Paths II

    62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...

  2. 刷题62. Unique Paths

    一.题目说明 题目62. Unique Paths,在一个m*n矩阵中,求从左上角Start到右下角Finish所有路径.其中每次只能向下.向右移动.难度是Medium! 二.我的解答 这个题目读读题 ...

  3. LeetCode 62. Unique Paths不同路径 (C++/Java)

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

  4. 62. Unique Paths

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

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

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

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

  9. 62. Unique Paths && 63 Unique Paths II

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

随机推荐

  1. Maven中的dependency的scope作用域

    1.test范围指的是测试范围有效,在编译和打包时都不会使用这个依赖 2.compile范围指的是编译范围有效,在编译和打包时都会将依赖存储进去 3.provided依赖:在编译和测试的过程有效,最后 ...

  2. TCP定时器 之 重传定时器

    注:这部分还没有完全分析透彻,先在此记录,后面回顾的时候再进行补充: 启动定时器: (1) 之前发送的数据段已经得到确认,新发出一个数据段之后设定: (2) 新建连接发送syn之后设定: (3) PM ...

  3. 2018092609-2 选题 Scrum立会报告+燃尽图 04

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/8682 一.小组情况组长:贺敬文组员:彭思雨 王志文 位军营 杨萍队名:胜 ...

  4. Windows下的Crontab表达式解析DLL的使用

    Linux的crontab工具特别的好用,正好现在工作总有好多定时执行的事 用Windows的定时任务觉得特别Low,哈哈,用C#写个任务触发器 然后再用上Crontab表达式解析DLL,觉得马上就高 ...

  5. AS之Lint 工具

    AndroidStudio内置的Lint工具,对app中的代码规范带来了极大的方便.对内存泄漏.代码冗余.代码安全.国际化.代码规范等很多方面都能检测,是一款非常强大的工具! 使用: 在AS--> ...

  6. logistic regression中的cost function选择

    一般的线性回归使用的cost function为: 但由于logistic function: 本身非凸函数(convex function), 如果直接使用线性回归的cost function的话, ...

  7. linux(centOS7)的基本操作(四) 定时任务——crontab

    概述 对于Java开发人员,定时任务并不陌生,无非是让系统在特定时间执行特定的命令或程序.例如spring提供的@Scheduled注解.OpenSymphony提供的quartz框架,都可以实现定时 ...

  8. I/O检测介绍

    I/O性能监测可总结如下:* 任何时间出现CPU等待IO,说明磁盘超载.* 计算出你的磁盘可维持的IOPS值.* 判定你的应用是属于随机磁盘访问型还是有序型.* 通过对比等待时间和服务时间即可判断磁盘 ...

  9. cocos2dx基础篇(25) 简单碰撞检测

    [3.x] 将数学类 CCPoint.CCRect 改为v3.x版本的 Vec2.Rect 就好了. [简单碰撞检测] 在一些游戏中经常会遇到碰撞检测的情况,如愤怒的小鸟飞出去后,是否与石头发生碰撞. ...

  10. Python学习之表的介绍

    9.4 表的介绍 存储引擎 数据的存储方式就是存储引擎,引擎不同,数据的存储方式就不同 MySQL中比较重要的引擎: InnoDB:mysql5.6以上,默认的存储方式 ​ 支持 transactio ...