https://programmers.co.kr/learn/courses/30/lessons/67258?language=python3
μ½λ©ν μ€νΈ μ°μ΅ - 보μ μΌν
["DIA", "RUBY", "RUBY", "DIA", "DIA", "EMERALD", "SAPPHIRE", "DIA"] [3, 7]
programmers.co.kr
νμ΄
λ¬Έμ λ₯Ό μ½κ³ , μ°μλ μ«μ => ν¬ ν¬μΈν° λ¬Έμ λλμ΄ λμ μ κ·Όνλλ μ½κ² ν μ μμμ΅λλ€.
PSλ₯Ό C++μμ νμ΄μ¬μΌλ‘ κ°μνμ§ μΌλ§ μλλλ°, νμ΄μ¬μ μλν¨μ λ€μ ν λ² λλ μ μμμ΅λλ€.
νμ΄μ¬ μ§ν©, λμ
λ리 λ무 νΈνλ€...
def solution(gems):
answer = []
s = set()
for gem in gems:
s.add(gem)
st, ed = 0, 0
d = {}
while ed < len(gems):
gem = gems[ed]
if gem in d:
d[gem] += 1
else:
d[gem] = 1
while st < ed:
gem = gems[st]
if d[gem] > 1:
d[gem] -= 1
st += 1
else:
break
if len(d) == len(s):
answer.append((st + 1, ed + 1))
ed += 1
return sorted(answer, key = lambda x: x[1] - x[0])[0]'Problem Solving π₯ > νλ‘κ·Έλλ¨Έμ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
| [νλ‘κ·Έλλ¨Έμ€] λ°°λ¬ / νμ΄μ¬ / (λ€μ΅μ€νΈλΌ μκ³ λ¦¬μ¦) (0) | 2021.01.29 |
|---|---|
| [νλ‘κ·Έλλ¨Έμ€] κΈ°μ§κ΅ μ€μΉ / νμ΄μ¬ (0) | 2021.01.29 |
| [νλ‘κ·Έλλ¨Έμ€] ν©μΉ νμ μκΈ / νμ΄μ¬ / (νλ‘μ΄λ μμ¬) (0) | 2021.01.26 |
| [νλ‘κ·Έλλ¨Έμ€] μΉ΄λ μ§ λ§μΆκΈ° / νμ΄μ¬ (2) | 2021.01.25 |
| [νλ‘κ·Έλλ¨Έμ€] λ°©λ¬Έ κΈΈμ΄ / νμ΄μ¬ (0) | 2021.01.24 |