mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Add Pascal's Triangle based solution for Unique Paths problem.
This commit is contained in:
13
src/algorithms/uncategorized/unique-paths/uniquePaths.js
Normal file
13
src/algorithms/uncategorized/unique-paths/uniquePaths.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import pascalTriangle from '../../math/pascal-triangle/pascalTriangle';
|
||||
|
||||
/**
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @return {number}
|
||||
*/
|
||||
export default function uniquePaths(width, height) {
|
||||
const pascalLine = width + height - 2;
|
||||
const pascalLinePosition = Math.min(width, height) - 1;
|
||||
|
||||
return pascalTriangle(pascalLine)[pascalLinePosition];
|
||||
}
|
||||
Reference in New Issue
Block a user