Created
July 18, 2020 00:19
-
-
Save germanescobar/edf49093d4062a3ad33f2e7e826f7df8 to your computer and use it in GitHub Desktop.
This file contains 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 numTilePossibilities = function(tiles) { | |
return rec(tiles) | |
}; | |
function rec(tiles) { | |
if (tiles.length === 1) { | |
return 1 | |
} | |
let sum = 0 | |
for (let i=0; i < tiles.length; i++) { | |
let result = rec(tiles.slice(0,i) + tiles.slice(i+1)) | |
sum += result + 1 | |
} | |
return sum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sabía que estaba muy cerca, la solución refactorizada es la siguiente:
Sólo necesitábamos ir guardando las letras y no repetir el proceso para las duplicadas!