๐งฎ PS
[ํ๋ก๊ทธ๋๋จธ์ค] (Python) - ์์ฃผํ์ง ๋ชปํ ์ ์ Lv1
Newmon
2021. 4. 23. 16:10
* ๋ฌธ์ ๋งํฌ
programmers.co.kr/learn/courses/30/lessons/42576
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ์์ฃผํ์ง ๋ชปํ ์ ์
์๋ง์ ๋ง๋ผํค ์ ์๋ค์ด ๋ง๋ผํค์ ์ฐธ์ฌํ์์ต๋๋ค. ๋จ ํ ๋ช ์ ์ ์๋ฅผ ์ ์ธํ๊ณ ๋ ๋ชจ๋ ์ ์๊ฐ ๋ง๋ผํค์ ์์ฃผํ์์ต๋๋ค. ๋ง๋ผํค์ ์ฐธ์ฌํ ์ ์๋ค์ ์ด๋ฆ์ด ๋ด๊ธด ๋ฐฐ์ด participant์ ์์ฃผํ ์ ์
programmers.co.kr
* ๋ฌธ์ ๋ถ๋ฅ , ๋์ด๋
๋ถ๋ฅ : ํด์
๋์ด๋ : Lv1
* ํ์ด์ฌ(Pyhton) ์ฝ๋
def solution(participant, completion):
participant = sorted(participant)
completion = sorted(completion)
for i in range(len(completion)):
if participant[i] != completion[i] :
answer = participant[i]
return answer
answer = participant[-1]
return answer
* ํ์ด ๋ฐฉ๋ฒ
- ์์ฃผํ์ง ๋ชปํ ์ฌ๋์ ํญ์ 1๋ช ์ด๋ค. -> ๋ฐ๋ผ์ len(participant) == len(completion) -1 ์ด ์ฑ๋ฆฝํ๋ค.
- 1๊ฐ์ ์์๋ง ์ ์ธํ๊ณ ๋ชจ๋ ์์๋ ๊ฐ์์ผํ๋ค. ๋ฐ๋ผ์ participant์ completion์ sort ํ ํ์
- for๋ฌธ์ ๋๋ฆฌ๋ฉด์ ๋ค๋ฅธ ์์๊ฐ ์๋์ง ํ์ํ๋ค.
- ๋ค๋ฅธ ์์๋ฅผ ๋ฐ๊ฒฌ์ return ํ๊ณ
- ๋ฐ๊ฒฌํ์ง ๋ชปํ๋ค๋ฉด participant์ ๋ง์ง๋ง ์์ (completion๋ณด๋ค 1๋งํผ ๋ ๊ธธ๊ธฐ ๋๋ฌธ์)๋ฅผ ๋ฆฌํดํ๋ค.