Skip to content

Commit c939f70

Browse files
committedDec 10, 2020
[Iterations] Codility-BinaryGap
1 parent 47c1198 commit c939f70

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
 

‎README.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
### 📖 [NOTES 바로가기](./notes)
88

9+
## Iterations
10+
11+
| # || Problem | Note |
12+
| :-: | :-: | :----------------------------------------------- | :--- |
13+
| 01 | | [Codility-Lesson1 BinaryGap](./src/Iterations/BinaryGap) | |
14+
915
## DFS & BFS
1016

1117
| # || Problem | Note |

‎src/Iterations/BinaryGap/Main.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package Iterations.BinaryGap;
2+
3+
public class Main {
4+
5+
public static void main(String[] args) {
6+
Solution s = new Solution();
7+
System.out.println(s.solution(1041));
8+
System.out.println(s.solution(8));
9+
}
10+
}
11+
12+
class Solution {
13+
public int solution(int N) {
14+
char[] binArr = Integer.toBinaryString(N).toCharArray();
15+
int ans = 0, start = 0;
16+
for (int i = 1; i < binArr.length; i++) {
17+
if (binArr[i] == '1') {
18+
ans = Math.max(ans, i - start - 1);
19+
start = i;
20+
}
21+
}
22+
return ans;
23+
}
24+
}

‎src/Iterations/BinaryGap/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [Codility - Lesson 1 Iterations] BinaryGap
2+
3+
![image](https://user-images.githubusercontent.com/22045163/101761832-f972b000-3b1f-11eb-80fd-7c05c6a919e2.png)

0 commit comments

Comments
 (0)
Please sign in to comment.