Last active
May 15, 2016 11:40
-
-
Save rsrini7/51630b17d8a2a75a4777db351b628d83 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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