Skip to content

Instantly share code, notes, and snippets.

@rsrini7
Last active May 15, 2016 11:40
Show Gist options
  • Select an option

  • Save rsrini7/51630b17d8a2a75a4777db351b628d83 to your computer and use it in GitHub Desktop.

Select an option

Save rsrini7/51630b17d8a2a75a4777db351b628d83 to your computer and use it in GitHub Desktop.
import scala.collection.JavaConversions._
// you can write to stdout for debugging purposes, e.g.
// println("this is a debug message")
object Solution {
def solution(N: Int): Int = {
val bin1 = N.toBinaryString
println(bin1)
var bin = bin1
if (bin1(bin1.length - 1) == '0') {
bin = bin1.substring(0, bin1.lastIndexOf('1'))
}
val binArr = bin.split("1")
println(binArr.length)
var len = 0;
for (b <- binArr) {
println(b)
if (len < b.length)
len = b.length;
}
len
}
def main(args: Array[String]) {
println(solution(readInt))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment