1. ๋ฌธ์ ์ค๋ช
์ ๋น์ด๋ ๊ฒ์์ ์ฆ๊ธฐ๋ ์ค ๊ฐ์ง๊ณ ์๋ ๋ฌผ๊ฑด์ด ๋๋ฌด ๋ง์ ์ฐฝ๊ณ ์ ๋ฆฌ๋ฅผ ํ๊ธฐ๋ก ํ์ต๋๋ค. ์ ๋น์ด๊ฐ ๋ณด์ ํ ๊ฒ์ ์ ์ฐฝ๊ณ ๋ ์ฌ๋ฌ ์นธ์ผ๋ก ๋๋์ด์ ธ ์๊ณ ๊ฐ ์นธ์๋ ๋ฌผ๊ฑด๋ค์ด ๋ด๊ฒจ์์ต๋๋ค. ์ฐฝ๊ณ ๋ฅผ ์ ๋ฆฌํ ๋ฐฉ๋ฒ์ ๊ณ ๋ฏผํ๋ ์ ๋น์ด๋ ๊ฐ์ ๋ฌผ๊ฑด์ด ์ฌ๋ฌ ์นธ์ ๋๋์ด ๋ค์ด์๋ ๊ฒ์ ๋ฐ๊ฒฌํ๊ณ ์ฐ์ ๊ฐ์ ๋ฌผ๊ฑด๋ผ๋ฆฌ ์ต๋ํ ๊ฒน์ณ์๋ ๋ฐฉ์์ผ๋ก ์ฐฝ๊ณ ๋ฅผ ์ ๋ฆฌํ๊ธฐ๋ก ํ์ต๋๋ค. ์ ๋น์ด์ ์ฐฝ๊ณ ์ ๋ค์ด์๋ ๋ฌผ๊ฑด์ ์ด๋ฆ๊ณผ ๊ฐ์๋ ๋ฆฌ์คํธ ํํ๋ก ์ฃผ์ด์ง๋ฉฐ, ํ ์นธ์ ๊ฒน์ณ์ง ์ ์๋ ๋ฌผ๊ฑด์ ๊ฐ์์๋ ์ ํ์ด ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.
์๋ฅผ ๋ค์ด ์ฐฝ๊ณ ์ ๊ฐ ์นธ์ ๋ด๊ฒจ์๋ ๋ฌผ๊ฑด์ ์ด๋ฆ์ด storage = ["pencil", "pencil", "pencil", "book"], ๊ฐ ๋ฌผ๊ฑด์ ๊ฐ์๊ฐ num = [2, 4, 3, 1]์ด๋ผ๋ฉด ์ฐํ๊ณผ ์ฑ ์ ํ ์นธ์ ๊ฐ๊ฐ ๊ฒน์ณ ์์ ๊ฐ๋จํ๊ฒ clean_storage = ["pencil", "book"], clean_num = [9, 1]๋ก ๋ง๋ค ์ ์์ต๋๋ค.
์ฃผ์ด์ง solution ํจ์๋ ์ ๋ฆฌ๋๊ธฐ ์ ์ฐฝ๊ณ ์ ๋ฌผ๊ฑด ์ด๋ฆ์ด ๋ด๊ธด ๋ฌธ์์ด ๋ฆฌ์คํธ storage์ ๊ฐ ๋ฌผ๊ฑด์ ๊ฐ์๊ฐ ๋ด๊ธด ์ ์ ๋ฆฌ์คํธ num์ด ์ฃผ์ด์ง ๋ , ์ ๋ฆฌ๋ ์ฐฝ๊ณ ์์ ๊ฐ์๊ฐ ๊ฐ์ฅ ๋ง์ ๋ฌผ๊ฑด์ ์ด๋ฆ์ return ํ๋ ํจ์์ ๋๋ค. solution ํจ์๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์๋ํ๋๋ก ํ ์ค์ ์์ ํด ์ฃผ์ธ์.
์ ํ์ฌํญ
- 1 ≤ storage์ ๊ธธ์ด = num์ ๊ธธ์ด ≤ 30
- storage[i]๋ ์์ด ๋์๋ฌธ์๋ก ์ด๋ฃจ์ด์ ธ ์์ต๋๋ค.
- ๋ฌผ๊ฑด์ ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ถํฉ๋๋ค. ์ฆ, "Book"๊ณผ "book"์ ์๋ก ๋ค๋ฅธ ๋ฌผ๊ฑด์ ๋๋ค.
- 1 ≤ storage[i]์ ๊ธธ์ด ≤ 30
- 1 ≤ num์ ๊ธธ์ด ≤ 20
- num[i]์๋ storage[i]์ ํด๋นํ๋ ๋ฌผ๊ฑด์ ๊ฐ์๊ฐ ๋ด๊ฒจ์์ต๋๋ค.
- ๊ฐ์ฅ ๊ฐ์๊ฐ ๋ง์ ๋ฌผ๊ฑด์ด ๋ ๊ฐ์ง ์ด์์ธ ๊ฒฝ์ฐ๋ ์์ต๋๋ค.
- ํ ์นธ์๋ ํ ์ข ๋ฅ์ ๋ฌผ๊ฑด๋ง ๋ค์ด๊ฐ ์ ์์ต๋๋ค.
2. ์ถ๋ ฅ ์์

3. ๋ฌธ์ ๋ต์
def solution(storage, num):
clean_storage = []
clean_num = []
for i in range(len(storage)):
if storage[i] in clean_storage:
pos = clean_storage.index(storage[i])
clean_num[pos] += num[i]
else:
clean_storage.append(storage[i]) # ๋ณ๊ฒฝ ์ clean_storage.append(num[i])
clean_num.append(num[i])
# ์๋ ์ฝ๋์๋ ํ๋ฆฐ ๋ถ๋ถ์ด ์์ต๋๋ค.
max_num = max(clean_num)
answer = clean_storage[clean_num.index(max_num)]
return answer