Last active
December 14, 2016 16:08
-
-
Save dahse89/4e2fa00ac4ea164ce7cd8878e7d19aa4 to your computer and use it in GitHub Desktop.
hackerrank stringSimilarity solution php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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