leetcode-mid-dynamic programming-62. Unique Paths
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的更多相关文章
- leetcode 62. Unique Paths 、63. Unique Paths II
62. Unique Paths class Solution { public: int uniquePaths(int m, int n) { || n <= ) ; vector<v ...
- 刷题62. Unique Paths
一.题目说明 题目62. Unique Paths,在一个m*n矩阵中,求从左上角Start到右下角Finish所有路径.其中每次只能向下.向右移动.难度是Medium! 二.我的解答 这个题目读读题 ...
- [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 ...
- 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 ...
- 【一天一道LeetCode】#62. Unique Paths
一天一道LeetCode系列 (一)题目 A robot is located at the top-left corner of a m x n grid (marked 'Start' in th ...
- [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 ...
- 【LeetCode】62. Unique Paths 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/unique-pa ...
- 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 ...
- [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 ...
- 【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 ...
随机推荐
- JavaScript concat() 方法
昨天接触了一个项目,我的tbody变量是一个数组,然后数据返回的是数组里面包含对象,我刚开始没看懂这个concat的作用,然后百度一下javascript中的用法,以此记录concat的方法: dat ...
- 优化 JS 条件语句及JS 数组常用方法, ---- 看完绝对对日后开发有用
前言: 日常所说的优化优化.最后我们到底优化了哪些,不如让我们从代码质量开始:个人觉得简洁简化代码其实觉得存在感挺强烈的QAQ 1. 获取URL中 ?后的携带参数: 这是我见过最简洁的了,若有更简洁的 ...
- Hibernate 最简单实例
我从网上下载了 hibernate-release-4.3.0.Final.zip,解压缩,把/lib/required文件夹下的所有jar包加入到eclipse项目中的Referenced Libr ...
- 牛客练习赛26B 烟花 (概率DP)
链接:https://ac.nowcoder.com/acm/contest/180/B 来源:牛客网 烟花 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5 ...
- 如何配置SQL Server数据库远程连接
本地数据库(SQL Server 2012或以上) 连接外网服务器的数据库,外网的服务器端需要做如下配置: 1.首先是要打开 数据的配置管理工具 2.配置相关的客户端协议,开启TCP/IP 3.数据库 ...
- VS2015加载错误的解决办法
在开始菜单中找到vs2015 的 vs2015 开发人员命令提示. 在命令提示符中输入 devenv /setup 然后回车,大概几分钟后可以执行完成 重启vs2015 发现问题解决.
- 如何将vim打造成Linux下的source insight
编写者:龙诗科 邮箱:longshike2010@163.com 2016-01-06 众所周知,windows下的source insight是阅读项目代码的神器,其神奇之处在于可以根据当前鼠标所指 ...
- 源于react里面constructor()和super()的使用
es5里面没有继承的话 //构造函数 function People(name,age){ this.age = age; this.name = name } let p1 = new People ...
- buuctf@test_your_nc
测试你的 nc 技巧 :)
- JAVA笔记19-容器之三 Set接口、List接口、Collections类、Comparable接口(重要)
一.Set接口 //HashSet综合举例 import java.util.*; public class Test{ public static void main(String[] args){ ...