# [TIL_Carrotww] 82 - 22/12/28

rjgjflΒ·2022λ 12μ 28μΌ
0

## TIL

97/119

### π Programmers νμ΄λΈ ν΄μ ν¨μ Level 2

def solution(data, col, row_begin, row_end):
data = sorted(data, key=lambda x:(x[col-1], -x[0]))
result = []
for i in range(len(data)):
data[i].append(i+1)
temp_data = data[row_begin - 1:row_end]
for i in temp_data:
i_temp = 0
for j in range(len(i) - 1):
i_temp += (i[j] % i[-1])
result.append(i_temp)

temp = result[0]
for i in result[1:]:
temp = temp ^ i

return temp

λ¬Έμ  μμ²΄λ₯Ό μ΄ν΄νλλ° λλ¬΄ μ€λκ±Έλ Έλ€. νΈλλ°λ μΌλ§ μκ±Έλ Έλλ°...
μ€λλ§μ νμ΄μ κ·Έλ°μ§ μ΄ν΄νκΈ° λν΄νλ€.

λ¬Έμ μμ μνλ λ°©μλλ‘ μ λ ¬μ ν΄μ€ ν
μ£Όμ΄μ§ λ²μλλ‘ xor νμ¬ κ°μ λ°ννλ©΄ λμ΄λ€.
javacriptμ reduce λΌλ ν¨μκ° μλλ° pythonμλ import νμ¬μ μ¬μ© κ°λ₯νλ€.
μΆ νμ λ€μ νμ΄λ΄μΌκ² λ€.

### π Programmers μΉ΄μΉ΄μ€ μΊμ Level2

def solution(cacheSize, cities):
cities = [x.lower() for x in cities]
cache = set()
result = 0
time = 0

for i in cities:
time += 1
temp_cache = [x[0] for x in cache]
if i in temp_cache:
for j in cache:
if i == j[0]:
cache.remove(j)
continue
result += 1
continue

result += 5
if len(cache) < cacheSize:
else:
if cacheSize < 2:
continue
Recent_val = min(cache, key=lambda x:x[1])
cache.remove(Recent_val)

return result

μ΄ λ¬Έμ λ λ³΄μλ§μ μ΄ν΄λ λ°λ‘ λμμ§λ§ μ΄μν κ³³μμ μκ°μ΄ λλ Έλ€ γ γ
λ¬Έμ μ λμλ¬Έμλ₯Ό κ΅¬λΆνμ§ μλλ€κ³  λμμμ΄ λμλ¬Έμλ₯Ό κ΅¬λΆνμ§ μμμ κ³μ μ€ν¨ν΄ μ’ λ§μ μκ°μ μ»κ³

λ¬Έμ μ ν€ ν¬μΈνΈ? λ LRU μΊμ κ΅μ²΄ μκ³ λ¦¬μ¦μ λ€μ΄λ΄€λ μ λμΈ κ² κ°λ€.

### π§² λλμ 

π μ€λλ§μ ν΄μ λ§μ΄ λΉμ¬μλ€. λΉ‘μΈκ² λ€μ λ¬λ¦¬μ

Carrot_hyeong