Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 30 | 31 |
Tags
- java
- Math.floor()
- 네트워크
- 프로그래머스 도둑질 java
- Math.ceil()
- 백준 18290
- java 반올림
- Codility
- java 올림
- 0으로 채우기
- 백준 15661
- Arrays
- 알고리즘
- 자바
- time complexity
- 프로그래머스 네트워크 java
- mysql
- 코딩테스트
- 백준 17425
- 프로그래머스 옹알이 java
- 백준 11723
- 백준 16927
- 백준 4375
- 백준 14391
- 백준 16935
- Algorithm
- 프로그래머스 숫자의 표현 java
- sort
- 프로그래머스 연속된 수의 합 java
- java 내림
Archives
- Today
- Total
취미처럼
[Codility] Lesson 1. Iterations - BinaryGap 본문
2진수의 1과 1사이의 간격 중 가장 큰 값을 찾는 문제
public static int solution(int N) {
String str = Integer.toBinaryString(N);
String[] arr = str.split("");
int totalGapLength = 0;
int gapLength = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i].equals("1")) {
if (gapLength > totalGapLength) {
totalGapLength = gapLength;
}
gapLength = 0;
} else if(arr[i].equals("0")) {
gapLength++;
}
}
return totalGapLength;
}
'Algorithm > Codility' 카테고리의 다른 글
[Codility] Lesson 3. Time Complexity - TapeEquilibrium (0) | 2021.03.29 |
---|---|
[Codility] Lesson 3. Time Complexity - PermMissingElem (0) | 2021.03.26 |
[Codility] Lesson 3. Time Complexity - FrogJmp (0) | 2021.03.26 |
[Codility] Lesson 2. Arrays - OddOccurrencesInArray (0) | 2020.02.19 |
[Codility] Lesson 2. Arrays - CyclicRotation (0) | 2020.02.19 |
Comments