You are viewing a single comment's thread. Return to all comments →
For PHP, this can be a solution as well. Thanks to @xXGoziXx
function makeAnagram($a, $b) { $counterArray = []; $occurrances = 0; for ($i=0;$i<strlen($a);$i++) { $counterArray[$a[$i]] = isset($counterArray[$a[$i]]) ? $counterArray[$a[$i]] + 1 : 1; } for ($i=0;$i<strlen($b);$i++) { if (isset($counterArray[$b[$i]]) && $counterArray[$b[$i]] > 0) { $counterArray[$b[$i]]--; $occurrances++; } } return (strlen($a) - $occurrances) + (strlen($b) - $occurrances); }
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 →
For PHP, this can be a solution as well. Thanks to @xXGoziXx