leetcode62.[DP] Unique Paths
2016-03-22 22:44
375 查看
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?
Ni,j=Ni−1,j+Ni,j−1N_{i,j}=N_{i-1,j}+N_{i,j-1}
当i=0i=0andj=0j=0时候Ni,j=1N_{i,j}=1
TLE代码
Accept代码
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?
Ni,j=Ni−1,j+Ni,j−1N_{i,j}=N_{i-1,j}+N_{i,j-1}
当i=0i=0andj=0j=0时候Ni,j=1N_{i,j}=1
TLE代码
class Solution(object): def uniquePaths(self, m, n): if m==1 or n==1: return 1 else: return self.uniquePaths(m-1,n)+self.uniquePaths(m,n-1)
Accept代码
class Solution(object): def uniquePaths(self, m, n): num=[] print num for i in range(m): num.append([]) for j in range(n): if i==0 or j==0: num[i].append(1) else: num[i].append(num[i][j-1]+num[i-1][j]) return num[m-1][n-1]
相关文章推荐
- Day4.2--Android高级UI控件之AutoCompleteTextView的使用
- 解决 Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
- iOS中UItableView 的重用机制原理
- poj Number Sequence 1019 (打表 &模拟)
- NGUI之UISprite
- 算法 加权quick-union
- codeforces_612C.Replace To Make Regular Bracket Sequence(stack)
- iOS开发-UUID
- leetcode303.[DP] Range Sum Query - Immutable
- Ngui使用粒子
- poj 2778:DNA Sequence
- ExtJs之Ext.query
- StringBuffer与StringBuilder详解
- haskell 安装gtk 适合win7GUI编程
- StringBuffer与StringBuilder详解
- 学习 ui-router - 管理状态
- UIButton 不可交互的几种情况 视图交互与不可交互的几种情况
- NGUI DrawCall
- Stanford CoreNLP – a suite of core NLP tools
- UE4官方视频学习日志:3rd Person Game with Blueprints