题目

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. 数据结构——UVA 1600 机器人巡逻

    描述 A robot has to patrol around a rectangular area which is in a form of mxn grid (m rows and n colu ...

  2. 网络协议- HTTP

    http:是用于www浏览的一个协议.tcp:是机器之间建立连接用的到的一个协议.

  3. [IE9] GPU硬件加速

      IE9 的一个重大改进就是使用了GPU硬件加速来渲染网页. 那么GPU硬件加速到底能够带来多大的性能提升? 你可以在IE的测试案例网站(http://ie.microsoft.com/testdr ...

  4. 怎样把redis编译为库,挪为己用?

    其实这是个伪命题.因为只要正常编译redis,那么在 /deps/hiredis/ 目录下就会生成动态库文件 libhiredis.so. 为了便于学习redis源码,编写一些测试程序,并进行单步跟踪 ...

  5. angularJS 指令二

    指令详解1.用directive()方法来定义指令.directive('myDirective',function($timeout,userDefinedService){ return {};} ...

  6. Vs 2008 对 OpenMP 的 支持 以及 OpenMP的环境变量及库函数

    Visual C++® 2008对OpenMP的支持 VC++2008根据项目属性配置的指示进行 /openmp编译器切换,当配置了OpenMP支持后,编译器会提供_OPENMP定义,可以使用#ifd ...

  7. UVa 496 Simply Subsets (STL&set_intersection)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=sh ...

  8. android编程中setLayoutParams方法设置

    第一篇 private LinearLayout generateHeadOfControl() { LinearLayout LayoutHead = createLayout(LinearLayo ...

  9. TCP/IP协议族-----10、搬家IP

  10. 《Android开发艺术探索》读书笔记 (7) 第7章 Android动画深入分析

    本节和<Android群英传>中的第七章Android动画机制与使用技巧有关系,建议先阅读该章的总结 第7章 Android动画深入分析 7.1 View动画 (1)android动画分为 ...