fun solution(N: Int): Int {
// 2進数に変換
val s = N.toString(2)
// sが0を含まないなら0を返す
if (!s.contains('0')) return 0
var max = 0
var count = 0
for(c: Char in s) {
// kotlinでの'0'と"0"は異なる
if (c.equals('0')) {
count++
} else if (max < count) {
max = count
count = 0
} else {
count = 0
}
}
return max
}
Last active
July 11, 2019 10:40
-
-
Save ochim/41bdc55c437e4253909e3bee2d000a2c to your computer and use it in GitHub Desktop.
BinaryGap
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment