You are viewing a single comment's thread. Return to all comments →
javascript
function makeAnagram(a, b) { let dictA = new Map(), dictB = new Map() let toBeDeleted = 0 for (let ch of a) { if (dictA.has(ch)) dictA.set(ch, dictA.get(ch) + 1) else dictA.set(ch, 1) } for (let ch of b) { if (dictB.has(ch)) dictB.set(ch, dictB.get(ch) + 1) else dictB.set(ch, 1) } dictA.forEach((v, k) => { if (!dictB.has(k)) toBeDeleted += v else if (dictB.get(k) < v) toBeDeleted += v - dictB.get(k) }) dictB.forEach((v, k) => { if (!dictA.has(k)) toBeDeleted += v else if (dictA.get(k) < v) toBeDeleted += v - dictA.get(k) }) return toBeDeleted }
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
javascript