Unique Paths

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?

 1 public class Solution {
 2     public int uniquePaths(int m, int n) {
 3         int steps[]=new int[n];
 4         steps[0]=1;
 5         for(int i=0;i<m;i++){
 6             for(int j=1;j<n;j++){
 7                 steps[j] = steps[j]+steps[j-1];
 8             }
 9         }
10         return steps[n-1];
11     }
12 }
View Code

 row should from 0

posted @ 2014-02-06 14:29  krunning  阅读(97)  评论(0编辑  收藏  举报