Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_zeros arr
- run = true
- count = 0
- temp = ""
- while run
- if arr[count].nil?
- temp = ""
- run = false
- elsif !(arr[count] == "1")
- temp += arr[count]
- else
- run = false
- end
- count += 1
- end
- temp.size
- end
- def binary_gap num
- result = []
- temp = num.to_s(2).split('')
- temp.each_with_index do |x, i|
- if x == "1"
- result << count_zeros(temp[i+1..-1])
- end
- end
- result.max
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement