Ad
Fundamentals
Logic
Code
Diff
  • function binaryGap($n) {
      $binary = trim(decbin($n), 0);
      preg_match_all('/[0]+/', $binary, $match);
      $max = 0;
      foreach ($match[0] as $zeros) {
        $max = max($max, strlen($zeros));
      }
      return $max;
    }
    • function binaryGap($n) {
    • $binary = trim(decbin($n), 0);
    • preg_match_all('/[0]+/', $binary, $match);
    • $max = 0;
    • foreach ($match[0] as $zeros) {
    • $max = max($max, strlen($zeros));
    • }
    • return $max;
    • }