Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ublic static int numPaths (int[][] mat,
- int x1, int y1, int x2, int y2)
- {
- return counterTracks(mat,x1,y1,x2,y2) ;
- }
- private static int counterTracks (int[][] mat,
- int x1, int y1, int x2, int y2)
- {
- if((x1<0 )||( y1<0 ) )
- {
- return 0;
- }
- if((x1 == mat.length )|| (y1 == mat.length))
- {
- return 0;
- }
- if((x1==x2) || (y1==y2))
- {
- return 1;
- }
- if(x1>y1)
- {
- return 0;
- }
- if(mat[x1][y1] == -1)
- {
- return 0;
- }
- int counter = mat[x1][y1];
- mat[x1][y1]=-1;
- int sum= counterTracks(mat,x1-1,y1,x2,y2) + counterTracks(mat,x1,y1-1,x2,y2)
- +counterTracks(mat,x1+1,y1,x2,y2) + counterTracks(mat,x1,y1+1,x2,y2);
- mat[x1][y1]= counter;
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement