Created
September 15, 2015 10:42
-
-
Save samuelcar/9296c0c97021c0d93e96 to your computer and use it in GitHub Desktop.
Solving the "Number of Paths" problem using JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var numberOfPaths = function(matrix, i, j, size) { | |
| var count = 0; | |
| if (i == size - 1 && j == size - 1) { | |
| return matrix[i][j]; | |
| } | |
| if (i == size - 1) { | |
| return matrix[i][j + 1] | |
| } | |
| if (j == size - 1) { | |
| return matrix[i + 1][j] | |
| } | |
| if (matrix[i][j] == 1) { | |
| return numberOfPaths(matrix, i + 1, j, size) + numberOfPaths(matrix, i, j + 1, size); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment