Algorithm for finding all paths in a NxN grid

前端 未结 10 1398
忘了有多久
忘了有多久 2020-11-28 08:27

Imagine a robot sitting on the upper left hand corner of an NxN grid. The robot can only move in two directions: right and down. How many possible paths are there for the ro

10条回答
  •  北海茫月
    2020-11-28 08:44

    int N;
    function num_paths(intx,int y)
    {
        int[][] arr = new int[N][N];
    arr[N-1][N-1] = 0;
    for(int i =0;i=0;i--)
    {
        for(int j=N-2;j>=0;j--)
        {
            arr[i][j]= arr[i+1][j]+arr[i][j+1];
        }
    }
    return arr[0][0];
     }
    

提交回复
热议问题