You are viewing a single comment's thread. Return to all comments →
I got a similar solution, but it's giving me an error on tests 5 and 12. I'm guessing because of memory errors.
Both mine and your solution are giving me the same errors though. How about you?
Here's my solution
function analizeContacts(){ this.contactObject = { letters: {}, data: 0 }; this.currentFinds = []; } analizeContacts.prototype.find = function(term){ const termChars = term.split(''); let currentWords = null; let searchObject = this.contactObject.letters; for( let i = 0; i < termChars.length; i++) { const el = termChars[i]; if(searchObject[el]) { currentWords = searchObject[el].data; searchObject = searchObject[el].letters; } else { currentWords = 0; break; } } if(currentWords !== null) { this.currentFinds.push(currentWords); } } analizeContacts.prototype.add = function(term) { const termChars = term.split(''); let searchObject = this.contactObject; for( let i = 0; i < termChars.length; i++) { const el = termChars[i]; if (!searchObject.letters[el]) { searchObject.letters[el] = {}; searchObject.letters[el].letters = {}; searchObject.letters[el].data = 1; } else { searchObject.letters[el].data++ } searchObject = searchObject.letters[el]; } } analizeContacts.prototype.results = function() { this.currentFinds.forEach((el) => { console.log(el); }); } function main() { var n = parseInt(readLine()); const analize = new analizeContacts(); for(var a0 = 0; a0 < n; a0++){ var op_temp = readLine().split(' '); var op = op_temp[0]; var contact = op_temp[1]; analize[op](contact); } analize.results() }
Tries: Contacts
You are viewing a single comment's thread. Return to all comments →
I got a similar solution, but it's giving me an error on tests 5 and 12. I'm guessing because of memory errors.
Both mine and your solution are giving me the same errors though. How about you?
Here's my solution