Skip to content

Instantly share code, notes, and snippets.

@dahse89
Last active December 14, 2016 16:08
Show Gist options
  • Save dahse89/4e2fa00ac4ea164ce7cd8878e7d19aa4 to your computer and use it in GitHub Desktop.
Save dahse89/4e2fa00ac4ea164ce7cd8878e7d19aa4 to your computer and use it in GitHub Desktop.
hackerrank stringSimilarity solution php
<?php
function stringSimilarity( $a) {
$a = trim($a);
$cutPrefix = $sum = 0;
$length = strlen($a);
do{
$count = 0;
while($a[$count] === substr($a,$cutPrefix+($count++), 1)){}
$sum += $count -1;
}while($cutPrefix++ < $length);
return $sum - 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment