ํ๋ก๊ทธ๋๋จธ์ค [lv1] ๋ก๋์์ต๊ณ ์์์์ต์ ์์ ํ์ด์ฌ
2021. 5. 18. 00:57ใ๐ฑ Algorithm/Else
2021 dev-matching์ ๋์จ ๋ฌธ์ ์ธ๋ฐ, ๋ํ ๋น์์๋ ํ๋์ ์ผ์ด์ค๋ก ์ธํด ํต๊ณผํ์ง ๋ชปํ๋ค.
14๋ฒ ์ผ์ด์ค๊ฐ ๋ฌธ์ ์ธ๋ฐ, ์ฐ์ ์ค๋ต์ฝ๋๋ฅผ ์ดํด๋ณด์.
์ค๋ต ์ฝ๋
def solution(lottos, win_nums):
count_zero = lottos.count(0)
count = [1 for num in lottos if num in win_nums]
if not count:
return [1, 6]
return [7 - (len(count) + count_zero), 7 - len(count)]
ํ๋๋ ๋ง์๊ฒ ์๋ค๋ ๊ฒ(count ๊ฐ 0)์ 2๊ฐ์ง๋ก ๋ถ๋ฅ ๋๋๋ฐ,
- lottos๊ฐ ๋ชจ๋ 0์ผ ๋ [1,6]์ด ๋๊ณ ,
- lottos์ 0์ด ํ๋๋ ์์ ๋, [6,6]์ด ๋๋ค.
์ด ์ ์ ๊ฐ๊ณผํ์ฌ 14๋ฒ ์ผ์ด์ค๋ฅผ ๋ซ์ง ๋ชปํ๋ค. (1๋ฒ ์ผ์ด์ค๋ง ์๊ฐํ๊ฑฐ์ง)
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ 2๋ฒ์ ๊ฒฝ์ฐ๋ฅผ ๊ณ ๋ คํ์ฌ ์์ธ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ๋ฉด ํต๊ณผํ ์ ์๋ค.
์ ๋ต ์ฝ๋
def solution(lottos, win_nums):
count_zero = lottos.count(0)
count = [1 for num in lottos if num in win_nums]
if (count_zero) == 6:
return [1, 6]
elif not count:
return [6, 6]
else:
return [7 - (len(count) + count_zero), 7 - len(count)]
๋ค๋ฅธ ์ฌ๋ ํ์ด
ํจ์ฌ ์ง๊ด์ ์ด๊ณ , lottos๋ฅผ win_nums์ ๋ง์ถ๋ ๊ฒ์ด ์๋ ๊ทธ ์ญ์ผ๋ก ์ ๊ทผํ๋ค.
def solution(lottos, win_nums):
rank=[6,6,5,4,3,2,1]
cnt_0 = lottos.count(0)
ans = 0
for x in win_nums:
if x in lottos:
ans += 1
return rank[cnt_0 + ans],rank[ans]
'๐ฑ Algorithm > Else' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 2003 ํ์ด์ฌ (0) | 2022.01.07 |
---|---|
๋ฐฑ์ค 10830 ํ์ด์ฌ (0) | 2021.12.26 |
ํ๋ก๊ทธ๋๋จธ์ค ๊ฐ๋ก๋ฑ ํ์ด์ฌ (0) | 2021.05.16 |
ํ๋ก๊ทธ๋๋จธ์ค [lv4] N-Queen ํ์ด์ฌ (0) | 2021.05.16 |
ํ๋ก๊ทธ๋๋จธ์ค [lv2] ๊ฐ์ฅ ํฐ ์ ์ฌ๊ฐํ ํ์ด์ฌ (0) | 2021.05.15 |