-
[Python] Codility Lesson1 - BinaryGap알고리즘, 자료구조/Codility 2022. 9. 19. 01:20
https://www.python.org/community/logos 문제: https://app.codility.com/programmers/lessons/1-iterations/binary_gap/
풀이
def solution(N): result = 0 binData = format(N, 'b') gapList = [] for i, v in enumerate(binData): if v == '1': gapList.append(i) if len(gapList) < 2: return result gapList.reverse() for i in range(len(gapList) - 1): tmp = gapList[i] - gapList[i + 1] - 1 if tmp > result: result = tmp return result
Javascript 풀이: https://jaejade.tistory.com/123?category=787340
[Javascript] Codility Lesson1 - BinaryGap
문제: https://app.codility.com/programmers/lessons/1-iterations/binary_gap/ 문제 요약 양의 정수인 N을 이진수로 나타냈을 때, 양 끝이 1로 이루어진 연속되는 0을 BinaryGap이라 한다. 가장 긴 BinaryGap의..
jaejade.tistory.com
'알고리즘, 자료구조 > Codility' 카테고리의 다른 글
[Javascript] Codility Lesson10 - CountFactors (0) 2022.08.20 [Javascript] Codility Lesson6 - Triangle (0) 2022.08.15 [Javascript] Codility Lesson1 - BinaryGap (0) 2022.07.19 [Javascript] Codility Lesson9 - MaxDoubleSliceSum (0) 2022.07.11 [Javascript] Codility Lesson9 - MaxSliceSum (0) 2022.06.22