题目

https://oj.leetcode.com/problems/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?
 

思路

每个到达终点的方案需要向右m-1步,向下n-1步,一共m+n-2步;
从组合角度,可以理解为从m+n-2中选择m-1步向右走,剩下n-1步向下走。
 

代码

 1 class Solution:
 2     # @return an integer
 3     def uniquePaths(self, m, n):
 4         return int(self.combination(m+n-2, n-1))
 5     
 6     def combination(self, n, k):
 7         res = 1.0
 8         for i in range(1, k+1):
 9             res = res * (n - k + i) / i
         return res
 
参考地址
1. https://oj.leetcode.com/discuss/9110/my-ac-solution-using-formula

【leetcode】62. Uniqe Paths的更多相关文章

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

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

  2. 【LeetCode】62. Unique Paths

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

  3. 【leetcode】62.63 Unique Paths

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

  4. 【LeetCode】63. Unique Paths II 解题报告(Python & C++)

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

  5. 【一天一道LeetCode】#62. Unique Paths

    一天一道LeetCode系列 (一)题目 A robot is located at the top-left corner of a m x n grid (marked 'Start' in th ...

  6. 【LeetCode】980. Unique Paths III解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

  7. 【LeetCode】797. All Paths From Source to Target 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

  8. 【LeetCode】63. Unique Paths II

    Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...

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

随机推荐

  1. HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)

    Problem Description You are given N baskets of gold coins. The baskets are numbered from 1 to N. In ...

  2. SRM 407(1-250pt, 1-500pt)

    DIV1 250pt 题意:每个员工可以有几个直系上司,也可以有几个直系下属.没有直系下属的人工资为1,有直系下属的人工资为所有直系下属工资之和.求所有人工资之和.人数 <= 50. 解法:直接 ...

  3. warning: Could not canonicalize hostname: vpn

    warning: Could not canonicalize hostname: vpn vim /etc/hosts 127.0.0.1 hostname

  4. kvm编译安装及常见问题解决

    一.KVM的编译安装 1.安装基本系统和开发工具 1.1 编译内核 mkdir /root/kvm cd /root/kvm wget http://www.kernel.org/pub/linux/ ...

  5. Node.js学习(7)----包

    包是在模块的基础上更深一步的抽象,Node.js的包类似于C/C++函数库或者Java/.NET的类库.它将独立的功能封装起来用于发布.更新.依赖管理和版本控制. Node.js的包是一个目录,其中包 ...

  6. Tomcat配置NIO

    tomcat的运行模式有3种.修改他们的运行模式.3种模式的运行是否成功,可以看他的启动控制台,或者启动日志.或者登录他们的默认页面http://localhost:8080/查看其中的服务器状态. ...

  7. java随机数与数组的使用。

    java随机数与数组的使用.    一:题目 二 代码:  public class Students {    int number;  // 学号    int State ;   // 年级   ...

  8. Leetcode - Reverse Words

    比起POJ弱爆了一题,从后往前扫描一遍,O(n)时间,仅仅要注意各种极端情况就可以,不明确通过率为什么仅仅有13%. #include<iostream> #include<stri ...

  9. VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号

    以下代码可以取得系统特征码(网卡MAC.硬盘序列号.CPU ID.BIOS编号) BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码 UINT uSys ...

  10. Git客户端(Windows系统)的使用

    本文环境: 操作系统:Windows XP SP3 Git客户端:TortoiseGit-1.8.5.0-32bit 一.安装Git客户端 全部安装均采用默认! 1. 安装支撑软件 msysgit:  ...