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
- 코딩테스트
- 백준 4375
- 백준 18290
- 백준 15661
- Codility
- 프로그래머스 네트워크 java
- mysql
- 프로그래머스 연속된 수의 합 java
- sort
- 백준 17425
- java 내림
- 알고리즘
- 자바
- 프로그래머스 도둑질 java
- Arrays
- java 올림
- 백준 11723
- 백준 16927
- 0으로 채우기
- Math.floor()
- Math.ceil()
- 프로그래머스 옹알이 java
- time complexity
- 백준 16935
- 프로그래머스 숫자의 표현 java
- 백준 14391
- java 반올림
- Algorithm
- 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