๋ฌธ์ ์ค๋ช
- ๋ฐฐ์ด
array์i๋ฒ์งธ ์ซ์๋ถํฐj๋ฒ์งธ ์ซ์๊น์ง ์๋ฅด๊ณ ์ ๋ ฌํ์ ๋,k๋ฒ์งธ์ ์๋ ์๋ฅผ ๊ตฌํ๋ ค ํฉ๋๋ค.
์๋ฅผ ๋ค์ด array๊ฐ [1, 5, 2, 6, 3, 7, 4], i = 2, j = 5, k = 3์ด๋ผ๋ฉด
array์ 2๋ฒ์งธ๋ถํฐ 5๋ฒ์งธ๊น์ง ์๋ฅด๋ฉด [5, 2, 6, 3]์
๋๋ค.
1์์ ๋์จ ๋ฐฐ์ด์ ์ ๋ ฌํ๋ฉด [2, 3, 5, 6]์
๋๋ค.
2์์ ๋์จ ๋ฐฐ์ด์ 3๋ฒ์งธ ์ซ์๋ 5์
๋๋ค.
๐ข ๋ฐฐ์ด arr์์ ์ฐ์์ ์ผ๋ก ๋ํ๋๋ ์ซ์๋ ์ ๊ฑฐํ๊ณ ๋จ์ ์๋ค์ return ํ๋ solution ํจ์๋ฅผ ์์ฑํด ์ฃผ์ธ์.
์ ํ์ฌํญ
array์ ๊ธธ์ด๋1์ด์100์ดํ์ ๋๋ค.array์ ๊ฐ ์์๋1์ด์100์ดํ์ ๋๋ค.commands์ ๊ธธ์ด๋1์ด์50์ดํ์ ๋๋ค.commands์ ๊ฐ ์์๋ ๊ธธ์ด๊ฐ3์ ๋๋ค.
์
์ถ๋ ฅ ์
์
์ถ๋ ฅ ์ #1, 2
[1, 5, 2, 6, 3, 7, 4]๋ฅผ2๋ฒ์งธ๋ถํฐ5๋ฒ์งธ๊น์ง ์๋ฅธ ํ ์ ๋ ฌํฉ๋๋ค.[2, 3, 5, 6]์ ์ธ ๋ฒ์งธ ์ซ์๋5์ ๋๋ค.[1, 5, 2, 6, 3, 7, 4]๋ฅผ4๋ฒ์งธ๋ถํฐ4๋ฒ์งธ๊น์ง ์๋ฅธ ํ ์ ๋ ฌํฉ๋๋ค.[6]์ ์ฒซ ๋ฒ์งธ ์ซ์๋ 6์ ๋๋ค.[1, 5, 2, 6, 3, 7, 4]๋ฅผ1๋ฒ์งธ๋ถํฐ7๋ฒ์งธ๊น์ง ์๋ฆ ๋๋ค.[1, 2, 3, 4, 5, 6, 7]์ ์ธ ๋ฒ์งธ ์ซ์๋ 3์ ๋๋ค.
Code : ๋ด๊บผ ๐ Logic ์ค๋ช
- ๋ฐ๋ณต๋ฌธ์ ๋๋ฉด์
commands์ ๊ฐ ์์command๋ฅผ ๊บผ๋ด์ดcommand๋ด์ ๊ฐ ์์๋ ๊ธฐ์กดarray๋ฅผ ์ฌ๋ผ์ด์ฑํstart,end, ๊ทธ๋ฆฌ๊ณ ์ฌ๋ผ์ด์ฑ๋ ๋ฆฌ์คํธ๋ฅผ ์ ๋ ฌ ํ ์ฐ๋ฆฌ๊ฐ ์ฐพ์ ์์์ ์์๋ฅผ ์๋ฏธ- ๋จ,
start,end,index๋ ์๋ฒ์ด ์๋Index No.์ ์๋ฏธํ๋ฏ๋ก ๊ทธ์ ๋ง๊ฒ ์กฐ์ ํด์ค์ผ ํจ.list comprehension์ ์ด์ฉํ์ฌ ๊ฐ๋จํ๊ฒ ์์ฑ- ์์ ๋ก์ง์ ์์๋๋ก ๊ตฌํ
> code
def solution(array, commands):
return [sorted(array[start-1:end])[index-1] for start,end,index in commands]
Code : ๋ค๋ฅธ ์ฌ๋๊บผ-
> code
๐ -
> code
๋ฌธ์ ์ค๋ช
0๋๋ ์์ ์ ์๊ฐ ์ฃผ์ด์ก์ ๋, ์ ์๋ฅผ ์ด์ด ๋ถ์ฌ ๋ง๋ค ์ ์๋ ๊ฐ์ฅ ํฐ ์๋ฅผ ์์๋ด ์ฃผ์ธ์.- ์๋ฅผ ๋ค์ด, ์ฃผ์ด์ง ์ ์๊ฐ
[6, 10, 2]๋ผ๋ฉด[6102, 6210, 1062, 1026, 2610, 2106]๋ฅผ ๋ง๋ค ์ ์๊ณ , ์ด์ค ๊ฐ์ฅ ํฐ ์๋6210์ ๋๋ค.
๐ข 0 ๋๋ ์์ ์ ์๊ฐ ๋ด๊ธด ๋ฐฐ์ด numbers๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ์์๋ฅผ ์ฌ๋ฐฐ์นํ์ฌ ๋ง๋ค ์ ์๋ ๊ฐ์ฅ ํฐ ์๋ฅผ ๋ฌธ์์ด๋ก ๋ฐ๊พธ์ด return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
์ ํ์ฌํญ
numbers์ ๊ธธ์ด๋1์ด์100,000์ดํ์ ๋๋ค.numbers์ ์์๋0์ด์1,000์ดํ์ ๋๋ค.- ์ ๋ต์ด ๋๋ฌด ํด ์ ์์ผ๋ ๋ฌธ์์ด๋ก ๋ฐ๊พธ์ด
returnํฉ๋๋ค.
์
์ถ๋ ฅ ์
Code : ๋ด๊บผ ๐ Logic ์ค๋ช
- ์ฃผ์ด์ง ์ซ์๋ค์ ์์๋ฆฌ ์๊ฐ ํฐ ๊ฒ๋ถํฐ ์์ ๋ฐฐ์ดํด์ผ ๊ทธ๊ฒ๋ค์ ์ด์ด ๋ถ์์ ๋ ๊ฐ์ฅ ํฐ ์๊ฐ ๋์ด.
- ๊ทธ๊ฒ์ ์ํด ์ฃผ์ด์ง ๋ฆฌ์คํธ์ ๊ฐ ์ซ์๋ค์ ํ์ ์ int ๊ฐ ์๋ str ์ผ๋ก ๋ณํ
- ๊ทธ ๋ค์์ ๋ฆฌ์คํธ๋ฅผ ์ญ์์ผ๋ก ์ ๋ ฌ์ ํ๊ฒ ๋๋ฉด, ์์๋ฆฌ ์ซ์๊ฐ ํฐ ๊ฒ๋ถํฐ ์ ๋ ฌํ๊ฒ ๋จ.
- ๊ทธ๋ฌ๋ ์์ ๋ฐฉ์๋๋ก ํ๊ฒ ๋๋ฉด 3, 30, 34๊ฐ ์ฃผ์ด์ก์ ๋ 34, 30, 3 ์์๋ก ์ ๋ ฌํ๊ฒ ๋๊ณ ์ด๋ 34, 3, 30 ์ ์ด์ด ๋ถ์ธ ์ซ์๋ณด๋ค ์๊ฒ๋จ. (34303 < 34330)
- ์ด๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด ๊ฐ ์ซ์๋ฅผ 3๋ฒ ์ด์ด ๋ถ์ฌ์ ์ต์ 3์๋ฆฌ ์ด์์ ์ซ์๋ฅผ ๋ง๋ค๊ณ , ๊ทธ ๊ฐ๋ค์ ํฌ๊ธฐ๋ฅผ ๋น๊ตํ์ฌ ์ญ์์ผ๋ก ์ ๋ ฌํ๋ฉด ๋จ.
- ์๋ํ๋ฉด, ์ ํ ์ฌํญ์ numbers์ ์์๋ 1000 ์ดํ์ ์ซ์๋ผ๋ ๋ด์ฉ์ด ์๊ธฐ ๋๋ฌธ
- ['3', '30', '34']์ ๊ฒฝ์ฐ, ๊ฐ ์์๋ฅผ 3๋ฒ์ฉ ์ด์ด ๋ถ์ด๋ฉด '333', '303030', '343434' ์ด ๋๊ณ , ์ด๋ฅผ ๋ฌธ์์ด์ ํฌ๊ธฐ๋ผ๋ ๊ธฐ์ค์ผ๋ก ์ญ์ ์ ๋ ฌํ๋ฉด '343434' > '333' > '303030' ์์ด ๋๊ธฐ ๋๋ฌธ์ ๋ฆฌ์คํธ ์ ๋ ฌ ๊ฒฐ๊ณผ๊ฐ ['34', '3', 30']์ด ๋จ.
- ์ฆ, 1 > 2 > 5 ์์๋๋ก ๋์ํ๊ฒ ์ฝ๋๋ฅผ ์์ฑํ๋ฉด ๋จ.
> code
def solution(numbers):
# ์ฃผ์ด์ง ๋ฆฌ์คํธ์ ๊ฐ ์์๋ฅผ ๋ฌธ์์ด๋ก ๋ณํ
numbers = list(map(str, numbers))
# lambda ํจ์๋ฅผ ์ด์ฉํ์ฌ ์ฃผ์ด์ง ๋ฆฌ์คํธ๋ฅผ ๊ฐ ์์๋ฅผ 3๋ฒ์ฉ ์ด์ด๋ถ์ธ ๊ฒฐ๊ณผ์ ์ญ์์ผ๋ก ์ ๋ ฌํ๊ฒ ๋จ.
numbers.sort(key=lambda x: x * 3, reverse=True)
# ๋ฆฌ์คํธ ๋ด์ ๋ฌธ์์ด์ ์ด์ด๋ถ์ธ ๋ค ์ ์๋ก ๋ณํ ํ ๋ค์ ๋ฌธ์์ด๋ก ๋ณํ
return str(int(''.join(numbers)))
Code : ๋ค๋ฅธ ์ฌ๋๊บผ๐ก ๋ ์์ ํฌ๊ธฐ๋ฅผ ๋น๊ตํ์ฌ 1/0/-1์ ๋ฐํํ๋ comparator ํจ์ ์์ฑ
๐ก functools ๋ชจ๋์ cmp_to_key ํจ์๋ฅผ ์ด์ฉํ์ฌ ๋ด๊ฐ ๋ง๋ ํจ์๋ก ์ปค์คํ
์ ๋ ฌ
return ๊ฐ์ ํญ์ 1/0/-1 ์ด์ด์ผ ํจ.
1: ์ ๋ ฌ ๊ธฐ์ค๋๋ก ์์ผ๋ก ๊ฐ๊ธฐ ์ํดTrue๋ฅผ ์๋ฏธ-1: ์ ๋ ฌ ๊ธฐ์ค๊ณผ ๋ฐ๋๋ก ๊ฐ์ ๋ค๋ก ๊ฐ๊ธฐ ์ํดFalse๋ฅผ ์๋ฏธ0:0์ ์์ ์ ๋ ฌ ๊ธฐ์ค์ ํด๋น๋์ง ์์ ๊ทธ๋๋ก ์์ ๋๋ฅผ
๐ก ์ฐธ๊ณ :
[Python] ์ปค์คํ ํ ๊ธฐ์ค์ผ๋ก sort()ํ๊ธฐ : cmp_to_key()
> code
import functools
# ์ปค์คํ
์ ๋ ฌ ํจ์ comparator ์์ฑ
def comparator(a,b):
print(f"a:{a}")
print(f"b:{b}")
# t1 : ๋ ๋ฌธ์์ด์ ์๋ฅผ ์์๋๋ก ์ด์ด ๋ถ์ธ ๊ฒฐ๊ณผ
t1 = a+b
# t2 : ๋ ๋ฌธ์์ด์ ์๋ฅผ ๋ฐ๋๋ก ์ด์ด ๋ถ์ธ ๊ฒฐ๊ณผ
t2 = b+a
print(f"int(t1) > int(t2) : {int(t1) > int(t2)}")
print(f"int(t1) < int(t2) : {int(t1) < int(t2)}")
print(f"๋น๊ต ๊ฒฐ๊ณผ : {result}")
print("==============================================")
# t1์ ์ซ์๊ฐ์ด ๋ ํฌ๋ค๋ฉด 1 : ๋ ํฐ ๊ฐ์ด ๋ค๋ก ์ด๋
# t2์ ์ซ์๊ฐ์ด ๋ ํฌ๋ค๋ฉด -1 : ๋ ํฐ๋์ด ์์ผ๋ก ์ด๋
# ๋ ๊ฐ์ด ๋์ผํ๋ค๋ฉด 0 : ์์๋ ๊ธฐ์กด๊ณผ ๋์ผ
return (int(t1) > int(t2)) - (int(t1) < int(t2))
def solution(numbers):
n = [str(x) for x in numbers]
n = sorted(n, key=functools.cmp_to_key(comparator),reverse=True)
answer = str(int(''.join(n)))
return answer
๐ ์์๋ฅผ ํตํ ํ์ธ
- ์์ ์ฝ๋์๋
์์๋ฅผ ํตํ ์ถ๋ ฅ ๋ด์ฉ ํ์ธnumbers = [3, 30, 34, 5, 9] solution(numbers) --- ์ถ๋ ฅ ๊ฒฐ๊ณผ --- a:5 b:9 int(t1) > int(t2) : False int(t1) < int(t2) : True ๋น๊ต ๊ฒฐ๊ณผ : -1 ============================================== a:34 b:5 int(t1) > int(t2) : False int(t1) < int(t2) : True ๋น๊ต ๊ฒฐ๊ณผ : -1 ============================================== a:30 b:34 int(t1) > int(t2) : False int(t1) < int(t2) : True ๋น๊ต ๊ฒฐ๊ณผ : -1 ============================================== a:3 b:30 int(t1) > int(t2) : True int(t1) < int(t2) : False ๋น๊ต ๊ฒฐ๊ณผ : 1 ============================================== a:3 b:5 int(t1) > int(t2) : False int(t1) < int(t2) : True ๋น๊ต ๊ฒฐ๊ณผ : -1 ============================================== a:3 b:34 int(t1) > int(t2) : False int(t1) < int(t2) : True ๋น๊ต ๊ฒฐ๊ณผ : -1 ============================================== a:3 b:30 int(t1) > int(t2) : True int(t1) < int(t2) : False ๋น๊ต ๊ฒฐ๊ณผ : 1 ============================================== --- return ๊ฐ --- '9534330'
๋ฌธ์ ์ค๋ช
- H-Index๋ ๊ณผํ์์ ์์ฐ์ฑ๊ณผ ์ํฅ๋ ฅ์ ๋ํ๋ด๋ ์งํ์ ๋๋ค.
- ์ด๋ ๊ณผํ์์
H-Index๋ฅผ ๋ํ๋ด๋ ๊ฐ์ธh๋ฅผ ๊ตฌํ๋ ค๊ณ ํฉ๋๋ค.์ํค๋ฐฑ๊ณผ1์ ๋ฐ๋ฅด๋ฉด,H-Index๋ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌํฉ๋๋ค.- ์ด๋ค ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ
nํธ ์ค,h๋ฒ ์ด์ ์ธ์ฉ๋ ๋ ผ๋ฌธ์ดhํธ ์ด์์ด๊ณ ๋๋จธ์ง ๋ ผ๋ฌธ์ดh๋ฒ ์ดํ ์ธ์ฉ๋์๋ค๋ฉดh์ ์ต๋๊ฐ์ด ์ด ๊ณผํ์์H-Index์ ๋๋ค.
๐ข ์ด๋ค ๊ณผํ์๊ฐ ๋ฐํํ ๋
ผ๋ฌธ์ ์ธ์ฉ ํ์๋ฅผ ๋ด์ ๋ฐฐ์ด citations๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ์ด ๊ณผํ์์ H-Index๋ฅผ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
์ ํ์ฌํญ
- ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ์ ์๋
1ํธ์ด์1,000ํธ์ดํ์ ๋๋ค.- ๋ ผ๋ฌธ๋ณ ์ธ์ฉ ํ์๋
0ํ์ด์10,000ํ์ดํ์ ๋๋ค.
์
์ถ๋ ฅ ์
์
์ถ๋ ฅ ์
- ์ด ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ์ ์๋
5ํธ์ด๊ณ , ๊ทธ์ค3ํธ์ ๋ ผ๋ฌธ์3ํ ์ด์ ์ธ์ฉ๋์์ต๋๋ค.- ๊ทธ๋ฆฌ๊ณ ๋๋จธ์ง
2ํธ์ ๋ ผ๋ฌธ์3ํ ์ดํ ์ธ์ฉ๋์๊ธฐ ๋๋ฌธ์ ์ด ๊ณผํ์์H-Index๋3์ ๋๋ค.
Code : ๋ด๊บผ Code 1
๐ Logic ์ค๋ช
์ฝ๋์ ์ง์ ์ ์
> code 1
def solution(citations):
# ์ธ์ฉ์ด ์ ๊ฒ ๋ ๋
ผ๋ฌธ๋ค๋ถํฐ ์์นญํ๊ธฐ ์ํด ์ ๋ ฌ
citations.sort()
# idx : ๋๋ณด๋ค ์ธ์ฉ๋ ์๊ฐ ์ ์ ๋
ผ๋ฌธ์ ์
# citation : ๋
ผ๋ฌธ์ ์ธ์ฉ๋ ํ์
for idx , citation in enumerate(citations):
# ์ธ์ฉ๋ ํ์๊ฐ ๋จ์ ๋
ผ๋ฌธ์ ์(๋๋ฅผ ํฌํจํ)๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ผ๋ฉด
if citation >= len(citations) - idx :
# ์ธ์ฉ๋ ๋
ผ๋ฌธ์ ์ซ์๋ฅผ return
return len(citations) - idx
# ๋
ผ๋ฌธ์ด 1ํธ๋ฐ์ ์๋ ๊ฒฝ์ฐ
return 0
Code 2
๐ Logic ์ค๋ช
> code 2
def solution(citations):
# ์ธ์ฉ์ด ๋ง์ด ๋ ๋
ผ๋ฌธ๋ค๋ถํฐ ์์นญํ๊ธฐ ์ํด ์ญ์์ผ๋ก ์ ๋ ฌ
citations.sort(reverse=True)
print(f"citations : {citations}")
print("=======~~=======")
for idx, citation in enumerate(citations):
print(f"idx : {idx}")
print(f"citation : {citation}")
print("========")
# H-Index๋ฅผ idx๋ผ๊ณ ๊ฐ์
# citation : ๋๋จธ์ง ๋
ผ๋ฌธ๋ค์ด ์ธ์ฉ๋ ํ์ ์ค ์ต๋๊ฐ
# ๋๋จธ์ง ๋
ผ๋ฌธ๋ค์ด ์ธ์ฉ๋ ํ์ ์ค ์ต๋๊ฐ์ด idx๋ฒ ์ดํ์ธ ์ต์ด์ ๊ฒฝ์ฐ๋ฅผ ์ฐพ์.
if idx >= citation:
# idx๋ฅผ ๋ฐํ
return idx
print(f"citations : {citations}")
print("--------")
# citations๋ฅผ ๋ชจ๋ ์์นญํ์๋๋ฐ H-Index ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ฐ์ด ์๋ค๋ฉด
# citations์ ๊ธธ์ด๋ณด๋ค ์์ ๊ฐ์ผ๋ก ๋ฆฌ์คํธ๋ฅผ 2๊ฐ๋๋ก ๊ตฌ๋ถ์ง์ ์ ์๋ค๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์
# citations์ ๊ธธ์ด๊ฐ ์ฐ๋ฆฌ๊ฐ ์ฐพ๋ H-Index
return len(citations)
๐ ์์๋ฅผ ํตํ ํ์ธ
- ์์ ์ฝ๋์๋
์์๋ฅผ ํตํ ์ถ๋ ฅ ๋ด์ฉ ํ์ธcitations = [6, 5, 5, 5, 3, 2, 1, 0] solution(citations) --- ์ถ๋ ฅ ๊ฒฐ๊ณผ --- citations : [6, 5, 5, 5, 3, 2, 1, 0] =======~~======= idx : 0 citation : 6 ======== idx : 1 citation : 5 ======== idx : 2 citation : 5 ======== idx : 3 citation : 5 ======== idx : 4 citation : 3 ======== --- return ๊ฐ --- '9534330'
Code : ๋ค๋ฅธ ์ฌ๋๊บผCode 1
citations ๋ฐฐ์ด์ ๋ชจ๋ ์ํํด์ผ ํ๋ฏ๋ก ์ข์ ์ฝ๋๋ ์๋.> code
def solution(citations):
# ์ต๋๊ฐ์ ๊ตฌํ๊ธฐ ์ํด max_๋ผ๋ ๋ณ์๋ฅผ ์ฌ์ฉ
# ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ฐ์ด ์๊ธธ๋๋ง๋ค ์ต๋๊ฐ์ผ๋ก ๊ฐฑ์ ํ์ฌ
max_ = 0
# ์ธ์ฉ๋ ๋
ผ๋ฌธ ์๊ฐ ๋ง์ ๊ฒ๋ถํฐ ํ์ํ๊ธฐ ์ํด ์ญ์์ผ๋ก ์ ๋ ฌ
citations.sort(reverse=True)
# index๋ฅผ 1๋ถํฐ ์์ํ๋ ์ด์ ๋, ๋๋ฅผ ํฌํจํ ๊ฐ์ ๊ณ์ฐํ๊ธฐ ์ํจ
for index, citation in enumerate(citations, start=1):
# index : ์ง๊ธ citation๋ณด๋ค ์ธ์ฉ๋ ํ์๊ฐ ํฌ๊ฑฐ๋ ๊ฐ์ ๋
ผ๋ฌธ์ ์
print(f"index : {index}")
# citation : ๋
ผ๋ฌธ์ ์ธ์ฉ๋ ํ์
print(f"citation : {citation}")
# (ํ์ฌ ๋
ผ๋ฌธ์ ์ธ์ฉ ํ์)๊ฐ (ํ์ฌ ๋
ผ๋ฌธ์ ์ธ์ฉ๋ ํ์ ์ด์์ผ๋ก ์ธ์ฉ๋ ๋
ผ๋ฌธ์ ์)๋ณด๋ค ๋ ํฌ๊ฑฐ๋ ๊ฐ๋ค๋ฉด
if citation >= index:
# H_index๊ฐ ๋ ์ ์๋ ํ๋ณด๋ก ๊ฐฑ์
# index๋ 1๋ถํฐ ์ ์ฐจ ์ปค์ง๊ณ , ์ต์ข
์ ์ผ๋ก ๋ง์กฑํ๋ ๊ฐ์ด max_์ ์ ์ฅ๋๋ฏ๋ก
# ๋ฐ๋ณต๋ฌธ ์ข
๋ฃ ํ ๊ฒฐ๊ตญ max_ ๊ฐ์ H-Index๋ฅผ ๋ง์กฑํ๋ ๊ฐ์ด ๋จ.
max_ = index
print(f"answer : {answer}")
return answer
Code 2
enumerate์ ์์์ 1๋ก ๋ง์ถค์ผ๋ก์จ, ๋ฐฐ์ด์ idx ์์ ๊ฐ ๊ฐ๊ฐ์ด ๋ฐ๋ก ๋๋ณด๋ค ์ธ์ฉ์ด ๋ง์ด๋ ๋
ผ๋ฌธ์ ํ์๋ฅผ ๋ปํ๊ฒ ๋จ.> code
def solution(citations):
citations.sort(reverse=True)
answer = max(map(min, enumerate(citations, start=1)))
return answer
์์
citation = [1,6,2,4,0]์ธ ๊ฒฝ์ฐ, ์ญ์์ผ๋ก ์ ๋ ฌํ๋ฉด[6,5,4,1,0]์ด ๋๊ณ ,enumerate(citations, start=1)ํจ์ ๋ก ์ธํด(1,6), (2,5), (3,4), (4,1), (5,0)์ ๊ฐ์ ๊ฐ์ฒด๊ฐ ์์ฑ๋จ.map(min, enumerate(citations, start=1))์ ๊ฒฐ๊ณผ,(1,2,3,1,0)์ด๋ผ๋ ๊ฐ์ฒด๊ฐ ์์ฑ๋จ.- ๊ฒฐ๊ณผ์ ์ผ๋ก
3์ดreturn๋จ.
ํด์
- ์์ ์ฝ๋๋ ๊ฐ๊ฐ์
(idx, citation)๊ฐ์ฒด์ ๋ํดx = 1๋ถํฐ ์์ํ์ฌy = index,y = citation๋ผ๊ณ ํ๋ ์ผ์ฐจ ํจ์๋ฅผ ๊ทธ๋ฆฐ ํ, ๊ฐ๊ฐ์x๊ฐ์ ๋ํดy๊ฐ์min๊ฐ๋ค๋ง ์ฒดํฌํ ๋ค์์ ๊ทธ ์ค์์max๊ฐ์ ์ฐพ์ ๊ฒฐ๊ณผ์.- https://ssuamje.tistory.com/47
โ ์ด ๋ธ๋ก๊ทธ์ ๊ด๋ จ๋ ๋ด์ฉ์ด ๋ ์์ธํ ์ ํ ์์ผ๋ ์ฐธ๊ณ ํ ๊ฒ.
๐