leetcode - Unique Paths
2015-12-29 15:50
387 查看
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?
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?
class Solution { public: int uniquePaths(int m, int n) { std::vector<std::vector<int>> dp(m,std::vector<int>(n,0)); for (int i = 0; i < m; i++) { dp[i][0] = 1; } for (int i = 0; i < n; i++) { dp[0][i] = 1; } for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { dp[i][j] = dp[i-1][j] + dp[i][j-1]; } } return dp[m-1][n-1]; } };
相关文章推荐
- Outlier Detection Techniques
- 详解 CALayer 和 UIView 的区别和联系
- Semantic UI 中Checkbox的选中等事件
- 解决 easyui datagrid 表格 url 中带有变量时,翻页功能异常
- 导航控制器切换影响UIScrollView布局
- break ,continue ,return 的区别及作用
- UEFI+GPT 修复 win10启动
- 文本框->UITextField 类的使用
- 自定义UIButton 图片与label的位置
- Android更新UI的四种方法
- 简化ui文件转换写法
- ios学习笔记UITableViewCell重用时出现重影的解决方案
- 用Fragment制作的Tab页面产生的UI重叠问题
- [友盟微博分享]does not contain bitcode. You must rebuild it with
- 键盘增加监听,UIButton随键盘位移
- iPhone 如何使用UIImageView播放动画,并停留在之后一张图片并添加播放结束时的事件
- HDU1159 Common Subsequence(动态规划)
- UILabel加载HTML文本和字体颜色修改
- Android官网:Configuring Gradle Builds英译
- UIViewController的生命周期及iOS程序执行顺序