Unique Paths [LeetCode]
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?

Above is a 3 x 7 grid. How many possible unique paths are there?
Note: m and n will be at most 100.
Solution: Pretty easy, use dynamic programming, from bottom line to top line, caculate every the path num of every cell.
class Solution {
public:
int uniquePaths(int m, int n) {
if(m <= || n <= )
return ;
vector<int> nums;
for(int i = ; i < m; i ++) {
if(i == ) {
for(int j = ; j < n; j++)
nums.push_back();
} else {
for(int j = ; j < n; j ++) {
nums[j] += nums[j - ];
}
}
}
return nums[n - ];
}
};
Unique Paths [LeetCode]的更多相关文章
- Unique Paths ——LeetCode
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- Unique Paths leetcode java
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [LeetCode] 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: Unique Paths II 解题报告
Unique Paths II Total Accepted: 31019 Total Submissions: 110866My Submissions Question Solution Fol ...
- LeetCode: Unique Paths I & II & Minimum Path Sum
Title: https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m ...
- 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】#63. Unique Paths II
一天一道LeetCode (一)题目 Follow up for "Unique Paths": Now consider if some obstacles are added ...
- 【一天一道LeetCode】#62. Unique Paths
一天一道LeetCode系列 (一)题目 A robot is located at the top-left corner of a m x n grid (marked 'Start' in th ...
随机推荐
- ps aux 查看进程信息
[root@localhost Desktop]# ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.3 ...
- excel在一个图表内,显示折线图和柱状图
折线图和柱状图,在同一个图表中拆分显示 一个图,设置主坐标轴 另外一个图,设置次坐标轴 拆分,通过调整纵坐标的最小值和最大值来实现 关于图表的标题,选中图表,选择布局,然后图表 ...
- 粒子群优化算法(Particle Swarm Optimization)
粒子群算法的思想源于对鸟/鱼群捕食行为的研究,模拟鸟集群飞行觅食的行为,鸟之间通过集体的协作使群体达到最优目的,是一种基于Swarm Intelligence的优化方法.它没有遗传算法的"交 ...
- linux Chrome 安装
1.wget 32bits: wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb 64bits: ...
- JAVA排序--[快速排序]
package com.array; public class Sort_Quick { /* * 项目名称:快速排序 ; * 项目要求:用JAVA对数组进行排序,并运用快速排序算法; * 作者:Se ...
- 5.5.3使用terminfo功能标志
当使用terminfo时,需要做的第一件事就是调用函数setupterm来设置终端类型.这将为当前的终端类型初始化一个TERMINAL结构.然后,你就可以查看当前终端的功能标志并使用他们的功能了. # ...
- Java开发中经典的小实例-(if(参数){}else{})
import java.util.Scanner; public class Calculate { public static void main(String[] args) { ...
- [SAP ABAP开发技术总结]将文件存储到数据库表中,并可发送邮件
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- Base64加密解密原理以及代码实现(VC++)
Base64加密解密原理以及代码实现 转自:http://blog.csdn.net/jacky_dai/article/details/4698461 1. Base64使用A--Z,a--z,0- ...
- mysql概要(二)类型
1.mysql数值型范围 tinyint可选属性 tinyint(N) unsigned zerofill N:表示显示长度,与zerofill配合使用,即长度不够用0填充,并且自动变成无符号的数,仅 ...