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 |
Tags
- 파이썬 주식
- JSON 형식
- 리눅스
- 빗썸 API 사용
- 트레이딩 봇 만들기
- 와스 웹서버의 차이
- Web Service Architecture
- string format
- 단순 반복 자동화
- JSON특징
- JavaScript Obejct Notation
- 리눅스 rwx
- Web Server란
- 변동성 돌파전략
- 프로그래머스
- 파이썬 가상환경
- 즐겨찾기가 가장 많은 식당 정보 출력하기
- Python
- spring
- WAS란
- pybithumb
- java
- beautifulsoup
- BigDecimal
- WAS WebServer 차이
- 오라클
- 프로그래머스 SQL
- 파이썬
- 리눅스 777
- 프로그래머스 소수
Archives
- Today
- Total
IT 개발자_S
[코딜리티] Binary Gap 본문
반응형
1. 입력값 N 입력후 Binary 값으로 변환
2. Binary 값으로 변환하기 위해 Integer 클래스의 toBinaryString 메소드 활용
3. binaryChar 배열 형태로 각각 정보를 입력받은 후
4. 배열의 값이 1인 경우 전 후 값을 비교하여 Binary Gap 값을 찾는다
// you can also use imports, for example:
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int N) {
// write your code in Java SE 8
String binaryString = Integer.toBinaryString(N);
char[] binaryChar = binaryString.toCharArray();
int temp_result =0;
int result =0;
int bFcheck = -1;
int aFcehck = -1;
// 1 0 0 0 0 0 1 0 0 0 1
for (int i =0; i <binaryChar.length; i++ ){
if(binaryChar[i] =='1' && bFcheck ==-1 ){
bFcheck = i;
}else if(binaryChar[i] =='1' ){
aFcehck = i;
temp_result = aFcehck -bFcheck -1;
if(result < temp_result) {
result = temp_result ;
}
bFcheck = i;
}
}
return result;
}
}
반응형
'IT > 알고리즘_JAVA' 카테고리의 다른 글
[코딜리티] TapeEquilibrium (0) | 2020.05.10 |
---|---|
[코딜리티]PermMissingElem (0) | 2020.05.10 |
[코딜리티]Frog_jump (0) | 2020.05.10 |
[코딜리티]OddOccurrencesInArray (0) | 2020.05.09 |
[코딜리티]CyclicRotation (0) | 2020.05.09 |
Comments