Leetcode 62. Unique Paths (Medium) (cpp)
2016-07-29 18:20
537 查看
Leetcode 62. Unique Paths (Medium) (cpp)
Tag: Array, Dynamic Programming
Difficulty: Medium
Tag: Array, Dynamic Programming
Difficulty: Medium
/* 62. Unique Paths (Medium) 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? */ class Solution { public: int uniquePaths(int m, int n) { if (m + n == 0) return 0; vector<int> res(n, 1); for (int i = 0; i < m; i++) { for (int j = 1; j < n; j++) { if ( i * j == 0) res[j] == 1; else res[j] = res[j - 1] + res[j]; } } return res[n - 1]; } };
相关文章推荐
- EasyUI 数字框
- Rescue
- EasyUI 组合网格
- 给手势UITapGestureRecognizer绑定tag
- EasyUI 组合框
- java设计模式——建造者模式(Builder Pattern)
- EasyUI 组合树
- EasyUI 组合
- Android 5.1 SystemUI 状态栏修改
- EasyUI 文本框、文件框和开关按钮
- ueditor 文本编辑器
- 98.Which two statements are true regarding the usage of the SQL*Loader utility? (Choose two.)
- Rescue hd 1242
- POJ 2031 Building a Space Station (最小生成树)
- EasyUI 验证框
- EasyUI 表单
- 蓝牙bluetooth之二-源码分布
- Android UI(ToggleButton)详解
- EasyUI 提示框
- EasyUI 进度条