From d2f23d1e203a33e5533cd5850a7b786605527f30 Mon Sep 17 00:00:00 2001 From: Vishal Date: Fri, 17 Apr 2020 18:38:21 +0400 Subject: [PATCH] Added binarygap.rb Converted your java code to ruby it work like 100% on codiality --- binarygap.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 binarygap.rb diff --git a/binarygap.rb b/binarygap.rb new file mode 100644 index 0000000..640b718 --- /dev/null +++ b/binarygap.rb @@ -0,0 +1,11 @@ +def solution(n) + collection_of_zero = [] + collection_of_zero = n.to_s(2)[0, n.to_s(2).rindex('1')].split("1") + x= 0 + a = 0 + while x < collection_of_zero.length + a = a > collection_of_zero[x].length ? a : collection_of_zero[x].length + x += 1 + end + a +end