일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- REM
- skt membership
- c
- grid
- Photoshop
- box-sizing
- 상태
- 확률
- Codility
- c++
- 소수
- 백준
- 통신사할인
- 알고리즘
- Javascript
- Gap
- pandas
- float
- transform
- 강화학습
- spring
- 포토샵
- react
- CSS
- 수학
- 미디어 쿼리
- JSX
- 반응형 웹
- stl
- SK바이오사이언스
Archives
- Today
- Total
sliver__
Codility : Lesson 1 (Iterator) 본문
728x90
안녕하세요~~
디벨로퍼입니다~~

오늘은 알고리즘 공부를 위해서 코딜리티 사이트에 접속했습니다.
오랜만에 푸는거라 긴장도 좀 되고 생각보다 힘겹지만
마음을 다잡고 시작해보았습니다
https://app.codility.com/programmers/
Developer Training | Test Coding Skills Online - Codility
Find longest sequence of zeros in binary representation of an integer.
app.codility.com
Lesson 별로 차례대로 풀어보려고 합니다~!
Lesson1 : Iterator 문제인 Binary Gap 문제를 풀어보았습니다.
1과 1사이의 연속적인 0의 개수를 구하는 문제입니다.
1의 시작과 그 사이에 있는 0의 개수를 세려하다보니
의도치 않게 코드가 깔끔하지 못한 것 같네요 ㅎㅎ;
아래는 제출한 코드입니다.
int solution(int N)
{
int temp = N, max = 0, answer = 0;
bool start, end;
start = end = false;
while(temp)
{
if(temp & 1)
{
if(start == false)
{
start = true;
}
else if(start == true)
{
if(max > answer) asnwer = max;
}
max =0;
}
else
{
max++;
}
temp >>= 1;
}
return answer;
}
하루에 한문제 씩 꾸준히 풀어보겠습니다.
이상 마무리하도록 하겠습니다~
감사합니다~!
728x90
'CS > Codility' 카테고리의 다른 글
Codility : Lesson 3 (Time complexity) - TapeEquilibrium (0) | 2021.09.27 |
---|---|
Codility : Lesson 3 (Time complexity) - PermMissingElem (0) | 2021.09.26 |
Codility : Lesson 3 (Time complexity) - FrogJmp (0) | 2021.09.25 |
Codility : Lesson 2 (Array) - OddOccurrencesInArray (0) | 2021.09.24 |
Codility : Lesson 2 (Array) - CyclicRotation (0) | 2021.09.23 |
Comments