Chapter12. ๊ตฌํ
[๋ฌธ์ 66] ๋จ์ ์นด๋ฉ๋ผ - Level3
๊ณ ์๋๋ก๋ฅผ ์ด๋ํ๋ ๋ชจ๋ ์ฐจ๋์ด ๊ณ ์๋๋ก๋ฅผ ์ด์ฉํ๋ฉด์ ๋จ์์ฉ ์นด๋ฉ๋ผ๋ฅผ ํ ๋ฒ์ ๋ง๋๋๋ก ์นด๋ฉ๋ผ๋ฅผ ์ค์นํ๋ ค๊ณ ํฉ๋๋ค.
๊ณ ์๋๋ก๋ฅผ ์ด๋ํ๋ ์ฐจ๋์ ๊ฒฝ๋ก routes๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ๋ชจ๋ ์ฐจ๋์ด ํ ๋ฒ์ ๋จ์์ฉ ์นด๋ฉ๋ผ๋ฅผ ๋ง๋๋๋ก ํ๋ ค๋ฉด ์ต์ ๋ช ๋์ ์นด๋ฉ๋ผ๋ฅผ ์ค์นํด์ผ ํ๋์ง๋ฅผ returnํ๋๋ก solution ํจ์๋ฅผ ์์ฑํ์ธ์.
์ฌ๋๋ค์ ๋ชธ๋ฌด๊ฒ๋ฅผ ๋ด์ ๋ฐฐ์ด people๊ณผ ๊ตฌ๋ช
๋ณดํธ์ ๋ฌด๊ฒ ์ ํ limit๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ๋ชจ๋ ์ฌ๋์ ๊ตฌ์ถํ๊ธฐ ์ํด ํ์ํ ๊ตฌ๋ช
๋ณดํธ ๊ฐ์์ ์ต์๊ฐ์ returnํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
[์ ํ์ฌํญ]
- ์ฐจ๋์ ๋์๋ 1๋ ์ด์ 10,000๋ ์ดํ
- routes์๋ ์ฐจ๋์ ์ด๋ ๊ฒฝ๋ก๊ฐ ํฌํจ๋์ด ์์ผ๋ฉฐ routes(i)(0)์๋ i๋ฒ์งธ ์ฐจ๋์ด ๊ณ ์๋๋ก์ ์ง์
ํ ์ง์ , routes(i)(1)์๋ i๋ฒ์งธ ์ฐจ๋์ด ๊ณ ์๋๋ก์์ ๋๊ฐ ์ง์ ์ด ์ ํ ์์ต๋๋ค.
- ์ฐจ๋์ ์ง์
/์ง์ถ์ง์ ์ ์นด๋ฉ๋ผ๊ฐ ์ค์น๋์ด ์์ด๋ ์นด๋ฉ๋ผ๋ฅผ ๋ง๋ ๊ฒ์ผ๋ก ๊ฐ์ฃผ
- ์ฐจ๋์ ์ง์
์ง์ , ์ง์ถ ์ง์ ์ -30,000 ์ด์ 30,000 ์ดํ
1. ์ฃผ์ด์ง ๋ฐ์ดํฐ๋ฅผ ์ง์ถ ์์ ์ผ๋ก ์ ๋ ฌ
def solution(routes):
routes = sorted(routes, key=lambda x: x[1])
last_camera = -30001
answer = 0
2. ์ ์ฐจ๋์ด ์ง์
ํ๋ ์ง์ ์์ ์นด๋ฉ๋ผ๊ฐ ์กด์ฌํ๋์ง ํ๋จ
for route in routes:
if last_camera < route[0]:
answer += 1
last_camera = route[1]
[์ ์ฒด์ฝ๋]
def solution(routes):
routes = sorted(routes, key=lambda x: x[1])
last_camera = -30001
answer = 0
for route in routes:
if last_camera < route[0]:
answer += 1
last_camera = route[1]
return answer