π 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 νμ¬μ μ¬μ© κ°λ₯νλ€.
reduceλ₯Ό μ¬μ©νλ©΄ μ΄μ€forλ¬Έμ μ¬μ©νμ§ μκ³ μ½λλ₯Ό μ’ λ μ€μΌ μ μλ€.
μΆ νμ λ€μ νμ΄λ΄μΌκ² λ€.
π 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) cache.add((i, time)) continue result += 1 continue result += 5 if len(cache) < cacheSize: cache.add((i, time)) else: if cacheSize < 2: continue Recent_val = min(cache, key=lambda x:x[1]) cache.remove(Recent_val) cache.add((i, time)) return result
μ΄ λ¬Έμ λ 보μλ§μ μ΄ν΄λ λ°λ‘ λμμ§λ§ μ΄μν κ³³μμ μκ°μ΄ λλ Έλ€ γ γ
λ¬Έμ μ λμλ¬Έμλ₯Ό ꡬλΆνμ§ μλλ€κ³ λμμμ΄ λμλ¬Έμλ₯Ό ꡬλΆνμ§ μμμ κ³μ μ€ν¨ν΄ μ’ λ§μ μκ°μ μ»κ³λ¬Έμ μ ν€ ν¬μΈνΈ? λ LRU μΊμ κ΅μ²΄ μκ³ λ¦¬μ¦μ λ€μ΄λ΄€λ μ λμΈ κ² κ°λ€.
π μ€λλ§μ ν΄μ λ§μ΄ λ Ήμ¬μλ€. λΉ‘μΈκ² λ€μ λ¬λ¦¬μ