1. 문제
https://programmers.co.kr/learn/courses/30/lessons/64062?language=python3
코딩테스트 연습 - 징검다리 건너기
[2, 4, 5, 3, 2, 1, 4, 2, 5, 1] 3 3
programmers.co.kr
2. 풀이
제귀가 아니라 그냥 반복문으로 풀 수있으면 반복문으로 끝내자...^^*
3. 코드
def countx(stones, target):
cnt = 0
max_cnt = 0
for i in stones:
if i < target :
cnt = cnt +1
else:
if (cnt > max_cnt):
max_cnt = cnt
cnt = 0
if (cnt > max_cnt):
max_cnt = cnt
return max_cnt
def solution(stones, k):
end = max(stones)
start = min(stones)
answer = 0
while (start <= end):
target = (start + end) // 2
p = countx(stones, target)
if (p >= k):
end = target -1
else:
answer =target
start = target +1
return answer
'ALGORITHM > Kakao' 카테고리의 다른 글
[Python] 수식 최대화 (0) | 2021.10.02 |
---|---|
[Python] 키패드 누르기 (0) | 2021.09.30 |
[Python] 괄호 변환 (0) | 2021.09.30 |
(C++) 행렬 테두리 회전하기 (0) | 2021.05.16 |
(C++ )2021 Dev-Matching 로또의 최고 순위와 최저 순위 (0) | 2021.05.13 |