Created
February 16, 2016 17:30
-
-
Save optyler/79b33c629bb74f563d7d to your computer and use it in GitHub Desktop.
Codinggame - Puzzles
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 N = +readline(); | |
var ROOT = {}; // All tree node with all numbers | |
var max = 0; // number of new keys in trees | |
for (let i = 0, CR; i < N; i++) { | |
CR = ROOT; // Current sub root elements with fragments of numbers, we always starts | |
var s = readline().split(''); | |
for(let j=0, len=s.length; j < len; j++) { | |
if (! CR.hasOwnProperty(s[j])) { // if the current branch have not the current number as a key, add it and increment counter | |
CR[s[j]] = {}; | |
++max; | |
} | |
CR = CR[s[j]]; | |
} | |
} | |
print(max); // The number of elements (referencing a number) stored in the structure. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment