Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Codility Bbinary Gap Test
function solution($N) {
// write your code in PHP5.5
$binaryNumber = decbin($N); // binary conversion of number
$trimmed = trim($binaryNumber, 0); // trim to remove trailing zeros
$binaryGap = explode("1",$trimmed); // explode
$binaryCount = array_map('strlen', $binaryGap);
return max($binaryCount); // returns the longest binary gap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.