Created
May 18, 2016 15:42
-
-
Save alabamaair/2ea8517d4d01a418a2d1386202560258 to your computer and use it in GitHub Desktop.
BinaryGap (Find longest sequence of zeros in binary representation of an integer) 80%score
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
def solution(n) | |
max = 0 | |
temp = n.to_s(2).split(/1/) | |
temp.each do |x| | |
if max < x.size | |
max = x.size | |
end | |
end | |
return max | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment