Created
October 5, 2016 07:40
-
-
Save NEbere/fbc744200f99d5b5fe850f44ebc0af6c to your computer and use it in GitHub Desktop.
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
// 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