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 ...
随机推荐
- tornado源码简单实现
首先基本的同步流程是: class Index(tornado.web.RequestHandle): def get(self): self.write('hellow,word') app = t ...
- luogu P2093 [国家集训队]JZPFAR
传送门 要维护平面上点的信息,所以可以用KD-tree来维护,然后维护一个大小为\(k\)的堆,每次从根开始遍历,遇到一个点就看能不能作为前\(k\)远的点,也就是看能不能把堆中最近的点给替换掉.如果 ...
- CRF++的使用(待更新)
1.下载CRF++(Windows和Linux两个版本) 2.目录如下: 主要用到crf_learn.exe ,crf_test.exe和libcrfpp.dll三个文件 doc文件夹:官方主页 ex ...
- chrom插件1
本文是稀土掘金投稿,虽然其中有倔金的私货,是篇推广文,但我看过后认为内容确实不错,有些好插件还是第一次知道,对我很有帮助,考虑过后还是决定推荐给大家,最近我比较关注各种提高开发效率的工具与技巧,今后看 ...
- Solaris下truss的使用
Solaris下truss的使用 原文转载:http://blog.csdn.net/sunlin5000/article/details/6560736 在Solaris下面,如果需要跟踪系统的调用 ...
- shell编程注意点
1.标准输入输出转存不能随便用,例如: echo "export PATH=/home/huangmr/jdk/bin:\$PATH" >> /home/huangmr ...
- Windows如何下载nginx软件包到linux系统虚拟机上
1.打开浏览器,输入“nginx下载官网” 2.点击nginx:download 3.找到你想下载的nginx软件包 4.点击你所需要的版本之后(我点击的是nginx-1.12.2版本,根据自己的需要 ...
- linux命令历史
本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群: 281442983 (点击链接加入群:http://jq.qq.com/?_wv=1027&k=29Lo ...
- 数据库管理哪家强?Devart VS Navicat 360°全方位对比解析
今天小编向大家推荐的是两个开发环节的主流数据库管理品牌,那么你知道这两款数据库管理软件品牌与数据库引擎配套的管理软件有什么区别吗?小编这就360°全方位为您解答: ★ 品牌介绍 Devart:拥有超过 ...
- Java中CharSet字符集
java.nio.charset包中提供了Charset类,它继承了Comparable接口:还有CharsetDecoder.CharsetEncoder编码和解码的类,它们都是继承Object类. ...