|
์ฝ๋ ์์ฑํ๊ธฐ
def solution(n, times) :
start=0
end=n*max(times)
while start<=end :
mid=(start+end)//2
total=0
for time in times :
total+=mid//time
if total>=n :
end=mid-1
else:
start=mid+1
return start
Python
๋ณต์ฌ
|
์ฝ๋ ์ค๋ช
ํ๊ธฐ
1.
start๋ 0 end๋ ๊ฐ์ฅ ์ค๋ ๊ฑธ๋ฆฌ๋ ์๊ฐ์ผ๋ก ์ ์ฅํ๋ค
2.
start๊ฐ end๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ๋๊น์ง ๋ฐ๋ณตํ๋ค.
a.
start์ end์ ์ค๊ฐ๊ฐ์ ๊ตฌํ๋ค.
b.
์ค๊ฐ๊ฐ์ ๊ธฐ์ค์ผ๋ก ์
๊ตญ์ฌ์ฌ๋ฅผ ๋ฐ์ ์ฌ๋์ ์๋ฅผ ๊ตฌํ๋ค.
c.
๊ตฌํ ์ฌ๋์ ์๊ฐ n๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ผ๋ฉด end ๊ฐ์ mid-1, n๋ณด๋ค ์์ผ๋ฉด start ๊ฐ์ mid+1๋ก ๋ฐ๊พผ๋ค.