Suffix tree: Difference between revisions

487 bytes removed ,  4 years ago
no edit summary
No edit summary
No edit summary
Line 732:
s += this.toString_f(children[children.length - 1], pre + ' ');
return s;
}
 
getLongestRepeatedSubString() {
return this.getLongestRepeatedSubString_f(0);
}
getLongestRepeatedSubString_f(n) {
let str = '';
for (const n2 of this.nodes[n].children.filter(n2 => this.nodes[n2].children.length > 0)) { // ignore leaves
const temp = this.getLongestRepeatedSubString_f(n2);
if (temp.length > str.length) {
str = temp;
}
}
return this.nodes[n].sub + str;
}
}
 
const st = new SuffixTree('banana');
console.log(st.toString());</lang>
console.log('>', st.getLongestRepeatedSubString());</lang>
 
{{out}}
Line 762 ⟶ 747:
└─┐ na
└─- na
 
> ana
</pre>
 
Anonymous user