Recent Posts
Recent Comments
목록BinaryGap java (1)
HEROJOON 블로그(히로블)

문제 Link: app.codility.com/programmers/lessons/1-iterations/binary_gap/ 가장 큰 이진 간격의 길이를 반환하라. ex) 10010001 일 경우 return 3; 만약 100000이라면 1과 1사이의 gap이 없으므로 return 0; 풀이 public int solution(int N) { String binaryStr = Integer.toBinaryString(N); char[] binaryCharArr = binaryStr.toCharArray(); int gap = 0; int maxGap = 0; for (char c: binaryCharArr) { if (c == '1') { if (maxGap < gap) { maxGap = gap; }..
코딩테스트
2020. 11. 4. 02:15