1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
class Solution {
public int solution(int N) {
// write your code in Java SE 8
boolean flag = false;
int len = 0, max_len = 0;
while(N > 0) {
int binary = N % 2;
if (binary == 1) {
if (!flag) {
flag = true;
}
else {
//뒤쪽의 1을 만남
max_len = max_len < len ? len : max_len;
len = 0;
}
}
else {
if (flag) len++;
}
N /= 2;
}
return max_len;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'Codility > JAVA' 카테고리의 다른 글
FlogJump (0) | 2020.02.16 |
---|---|
TapeEquilibrium (0) | 2020.02.15 |
OddOccurencesInArray (0) | 2020.02.15 |
Cyclic Rotation (0) | 2020.02.15 |