[LeetCode]Unique Paths II
2015-12-04 16:42
483 查看
public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int row = obstacleGrid.length; if (row == 0) { return 0; } int col = obstacleGrid[0].length; if (obstacleGrid[0][0] == 1) { return 0; } int[][] record = new int[row][col]; record[0][0] = 1; for (int r = 1; r < row; r++) { if (obstacleGrid[r][0] == 1 || record[r - 1][0] == 0) { } else { record[r][0] = record[r - 1][0]; } } for (int c = 1; c < col; c++) { if (obstacleGrid[0][c] == 1 || record[0][c - 1] == 0) { } else { record[0][c] = record[0][c - 1]; } } for (int r = 1; r < row; r++) { for (int c = 1; c < col; c++) { if (obstacleGrid[r][c] == 1) { record[r][c] = 0; } else { record[r][c] = record[r - 1][c] + record[r][c - 1]; } } } return record[row - 1][col - 1]; } }
相关文章推荐
- Android属性之build.prop生成过程
- EsayUI datagrid 刷新问题
- 初探物联网 - 基于Arduino的气象站和View and Data API的结合实例
- iOS上架准备工作(一)--版本号和编译号 (Version Numbers and Build Numbers)
- Builder design pattern in java
- Ubuntu ROS Arduino Gazebo学习镜像iso说明(indigo版)
- Ubuntu ROS Arduino Gazebo学习镜像iso说明(indigo版)
- Ubuntu ROS Arduino Gazebo学习镜像iso说明(indigo版)
- UIImageJPEGRepresentation和UIImagePNGRepresentation
- NSData、 UIImage、ALAsset之间的关系和转化
- ERROR 1269 (HY000): Can't revoke all privileges for one or more of the requested users
- Obtaining, Configuring and Building unixODBC
- 通过实现一个TableView来理解iOS UI编程
- hdu 1159 Common Subsequence
- 关于easyui textbox赋值
- Handler、Looper、MessageQueue
- UI进阶之模拟时钟指针案例
- UITableView最上面tableHeaderView留空间的两种方法
- 你好,色彩 android:background="@color/white" [create file color.xml at res/values/]
- 解决"The server quit without updating PID file."