mycode   time limited

class Solution(object):
def uniquePaths(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
"""
if not m or not n :
return 0
if m == 1 or n == 1:
return 1
return self.uniquePaths(m-1,n) + self.uniquePaths(m,n-1)

参考:

思路: 类似于金字塔那个题,考虑上一步即可

class Solution(object):
def uniquePaths(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
"""
if m == 1 and n == 1:
list = [[1]]
elif m == 1 and n > 1:
list = [[1 for i in range(n)]]
elif m > 1 and n == 1:
list = [[1] for i in range(m)]
else:
list = [[0 for i in range(n)] for i in range(m)]
for i in range(0, n):
list[0][i] = 1
for i in range(0, m):
list[i][0] = 1
for i in range(1, m):
for j in range(1, n):
list[i][j] = list[i-1][j] + list[i][j-1]
return list[m-1][n-1]

leetcode-mid-dynamic programming-62. Unique Paths的更多相关文章

  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 不同的路径

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

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

  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] 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 解题报告(Python & C++)

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

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

  9. [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 ...

  10. 【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 ...

随机推荐

  1. Bootstrap中DropDown插件显示下拉列表,点击下拉列表区域,不会再自动关闭。

    目标: Bootstrap中DropDown插件显示下拉列表,点击下拉列表区域,不会再自动关闭. 参考:http://v3.bootcss.com/javascript/#dropdowns    / ...

  2. Homebrew学习(二)之安装、卸载、更新

    安装 1.网上的安装方法都是用curl,从官网找到命令复制到终端,然后回车,结果报错请求超时 /usr/bin/ruby -e "$(curl -fsSL https://raw.githu ...

  3. HTML5的几大新特性

    为了更好地处理今天的互联网应用,HTML5添加了很多新元素及功能,比如: 图形的绘制,多媒体内容,更好的页面结构,更好的形式 处理,和几个api拖放元素,定位,包括网页 应用程序缓存,存储,网络工作者 ...

  4. vue项目1-pizza点餐系统4-二级、三级路由

    一.目标样式 二.二级路由 在“关于我们”(about)下面设置二级路由. 1.创建组件,在router文件夹中index.js中先导入组件,配置好路由的访问地址,名称. //二级路由 import ...

  5. npm切换淘宝镜像源

    npm 切换到淘宝源地址默认的npm下载地址:http://www.npmjs.org/淘宝npm镜像的地址:https://npm.taobao.org/ 临时使用淘宝源npm --registry ...

  6. mycat的wrapper.log日志中发现主从切换报错

    可能是MySQL在某些情况下重启(密切关注重启现象,关注日志,找出原因),导致mycat切换主从.由于设置了单向主从,mycat将从库切换为主库,原来的主库宕机.后来重新更新dnindex.conf之 ...

  7. 2019-11-29-dotnet-使用-Qpush-快速从电脑到手机推送文字

    title author date CreateTime categories dotnet 使用 Qpush 快速从电脑到手机推送文字 lindexi 2019-11-29 08:58:57 +08 ...

  8. 关于session和cookie的区别

    以前对于session和cookie的认识,就只是粗略的知道cookie保存在客户端,而session则保存在服务端. 如今查了些资料,对session和cookie也有了一个初步的认识,现在来总结一 ...

  9. pandas的基本功能

    一.重新索引 (1)reindex方式 obj = pd.Series(['blue', 'purple', 'yellow'], index=[0, 2, 4]) print(obj) obj.re ...

  10. mongodb,robomongo 数据查询

    可视化管理工具:Robomongo 是开源,免费的MongoDB管理工具,下载地址:Robomongo下载 1.  基本查询:    构造查询数据.    > db.test.findOne() ...