You are viewing a single comment's thread. Return to all comments →
Here is the PHP version of your solution
function sherlockAndAnagrams($s) { $anagrams = 0; $found = []; for($i=0; $i<strlen($s); $i++) { for($j = 0; ($j + $i) <= strlen($s); $j++) { $sub = substr($s, $i, $j); $sub = str_split($sub); sort($sub); $sub = implode('', $sub); if($sub != '') { if(isset($found[$sub])) { $anagrams += $found[$sub]; $found[$sub]++; } else { $found[$sub] = 1; } } } } return $anagrams; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
Here is the PHP version of your solution