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. Datatable分页

    using System; using System.Collections.Generic; using System.Web; using System.Data; /// <summary ...

  2. Lambda表达式之Python

    一.lambda函数 1.lambda函数基础: lambda函数也叫匿名函数,即,函数没有具体的名称,而用def创建的方法是有名称的.如下: """命名的foo函数&q ...

  3. 基本的DMA控制器

    DMA的基本概念 直接内存访问(DMA)是一种完全由硬件执行I/O交换的工作方式.在这种方式中,DMA控制器从CPU完全接管对总线的控制,数据交换不经过CPU,而直接在内存和I/O设备之间进行 .DM ...

  4. chainOfResponsibility责任链模式

    责任链(Chain of Responsibility)模式 : 责任链模式是对象的行为模式.使多个对象都有机会处理请求,从而避免请求的发送者和接受者直接的耦合关系.将这些处理对象连成一条链,沿着这条 ...

  5. HTML笔记(七)head相关元素<base> & <meta>

    <head>元素是所有头部元素的容器. 可添加的标签有:<title>.<base>.<link>.<meta>.<script> ...

  6. iOS - OC NSString 字符串

    前言 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSSecureCoding> @interface NSM ...

  7. 设计js通用库

    设计js通用库的四个步骤: 1.需求分析:分析库需要完成的所有功能. 2.编程接口:根据需求设计需要用到的接口及参数.返回值. 3.调用方法:支持链式调用,我们期望以动词方式描述接口. (ps:设计链 ...

  8. (八)C语言结构体和指针

    指针也可以指向一个结构体变量.定义的一般形式为: struct 结构体名 *变量名; 前面已经定义了一个结构体 stu: struct stu { char *name; int num; char ...

  9. 【转载】C++异常机制的学习

    参考了这篇文章:http://blog.chinaunix.net/uid-24517549-id-4079174.html 关于线程 进程和线程的概念相信各位看官早已耳熟能详.在这里,我只想带大家回 ...

  10. iOS开发之 XCode6.0的iOS免证书真机测试方法(MAC及黑苹果均有效)

    参考:http://mobile.51cto.com/iphone-455500.htm XCode6.0的iOS免证书真机测试方法(MAC及黑苹果均有效) 前提:设备已经越狱 目前在XCode上开发 ...