티스토리 뷰

function solution($N) { $max = 0; $cnt = array(); $bin_num = array(); $re_bin_num = array(); if ($N > 0) { while ( $N > 1) { $bin_num[] = $N % 2; $N = $N / 2; } } if (sizeof($bin_num) > 0) { $size = sizeof($bin_num)-1; $idx = 0; for ($i = $size ; $i >= 0 ; $i--) { if ($bin_num[$i]) { if (sizeof($cnt) > 0 && $cnt[$idx] > 0) { $max = $max < $cnt[$idx] ? $cnt[$idx] : $max; $idx++; } $cnt[$idx] = 0; } else $cnt[$idx]++; } } return $max; }


https://app.codility.com/demo/results/trainingW6AZKE-FPB/

댓글