728x90 기업코딩테스트1 [Codility][C] BinaryGap 전체 성공 코드 int getMax(int a , int b) { return a > b ? a : b; } int solution(int N) { // write your code in C99 (gcc 6.2.0) int flag = 0; int temp = 0; int max_value = 0; while(N != 1) { if (N % 2 == 0) { if (flag) { temp++; max_value = getMax(max_value, temp); } } else { // N % 2 == 1 if (!flag) { flag = 1; } else { temp = 0; } } N = N / 2; } return max_value; } 결과 화면 2020. 12. 22. 이전 1 다음 728x90