题目来源


https://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?


题意分析


Input:m、n

Output:the number of unique path

Conditions:输出所有可能的路径


题目思路


一看想起了全排列,注意到(m=3,n=7)时,表示要向下2步向右6步,那么全排列可得路径为f(2+6)/(f(2)*f(6)),f为阶乘函数


AC代码(Python)


 __author__ = 'YE'

 class Solution(object):
def uniquePaths(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
"""
def fac(n):
f = 1
for i in range(1, n + 1):
f *= i
return f m -= 1
n -= 1
if m == 0 or n == 0:
return 1
return fac(m + n) / (fac(m) * fac(n)) print(Solution().uniquePaths(3, 7))

[LeetCode]题解(python):062 Unique path的更多相关文章

  1. [Leetcode 62]机器人走路Unique Path 动态规划

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

  2. LeetCode 63. Unique Path II(所有不同路径之二)

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  3. [LeetCode 题解]:Path Sum

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a bi ...

  4. 【LeetCode题解】二叉树的遍历

    我准备开始一个新系列[LeetCode题解],用来记录刷LeetCode题,顺便复习一下数据结构与算法. 1. 二叉树 二叉树(binary tree)是一种极为普遍的数据结构,树的每一个节点最多只有 ...

  5. 【LeetCode题解】3_无重复字符的最长子串(Longest-Substring-Without-Repeating-Characters)

    目录 描述 解法一:暴力枚举法(Time Limit Exceeded) 思路 Java 实现 Python 实现 复杂度分析 解法二:滑动窗口(双指针) 思路 Java 实现 Python 实现 复 ...

  6. 【LeetCode题解】225_用队列实现栈(Implement-Stack-using-Queues)

    目录 描述 解法一:双队列,入快出慢 思路 入栈(push) 出栈(pop) 查看栈顶元素(peek) 是否为空(empty) Java 实现 Python 实现 解法二:双队列,入慢出快 思路 入栈 ...

  7. 【LeetCode题解】232_用栈实现队列(Implement-Queue-using-Stacks)

    目录 描述 解法一:在一个栈中维持所有元素的出队顺序 思路 入队(push) 出队(pop) 查看队首(peek) 是否为空(empty) Java 实现 Python 实现 解法二:一个栈入,一个栈 ...

  8. 【LeetCode题解】844_比较含退格的字符串(Backspace-String-Compare)

    目录 描述 解法一:字符串比较 思路 Java 实现 Python 实现 复杂度分析 解法二:双指针(推荐) 思路 Java 实现 Python 实现 复杂度分析 更多 LeetCode 题解笔记可以 ...

  9. 【LeetCode题解】25_k个一组翻转链表(Reverse-Nodes-in-k-Group)

    目录 描述 解法一:迭代 思路 Java 实现 Python 实现 复杂度分析 解法二:递归(不满足空间复杂度) 思路 Java 实现 Python 实现 复杂度分析 更多 LeetCode 题解笔记 ...

随机推荐

  1. extjs grid

    Ext.onReady(function() { Ext.BLANK_IMAGE_URL = '../resources/images/default/s.gif'; Ext.QuickTips.in ...

  2. 关于Web Worker你必须知道的7件事

    介绍 通过使用Web Worker, 我们可以在浏览器后台运行Javascript, 而不占用浏览器自身线程.Web Worker可以提高应用的总体性能,并且提升用户体验.如果你想在自己的Web应用中 ...

  3. Codeforces Round #203 (Div. 2) A.TL

    #include <iostream> #include <algorithm> using namespace std; int main(){ int n,m; cin & ...

  4. 【wikioi】1230 元素查找(巨水题+set/hash)

    http://wikioi.com/problem/1230/ 这题我真的不好意思写题解了...set练手.. #include <cstdio> #include <set> ...

  5. CentOS GO 语言环境的搭建

    go 语言源码安装依赖 ,gcc ,make glibc库,等,上述工具安装省略, 这个是官方地址:http://www.golang.org/ 另外,其源代码更新采用的是mercurial 工具,安 ...

  6. 在thinkphp框架模板中引用session

    我已经将模板引擎配置为smarty,在模板中使用常量是写为 {$smarty.const.ADMIN_IMG} 到使用到session的值时这样写 {$smarty.session.mg_name}

  7. FreeBSD Intel SYSRET Kernel Privilege Escalation Exploit

    /* * FreeBSD 9.0 Intel SYSRET Kernel Privilege Escalation exploit * Author by CurcolHekerLink * * Th ...

  8. Html - 返回Top

    制作浮动top $(window).scroll( function() { var scrollValue=$(window).scrollTop(); scrollValue > 600 ? ...

  9. The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

    xmpp 项目中遇到的问题,用苹果的通信API 写一个PUT 方法,向服务器上传一张图片.遇到如题问题. Plist 文件没有NSAppTransportSecurity属性 Dic,添加该属性,再添 ...

  10. jQuery EasyUI DataGrid Checkbox 数据设定与取值

    纯粹做个记录,以免日后忘记该怎么设定. 这一篇将会说明两种使用 jQuery EasyUI DataGrid 的 Checkbox 设定方式,以及在既有数据下将 checked 为 true 的该笔数 ...