Open robert-min opened 1 year ago
풀이 : cacheSize == 0 일때, 예외처리
def solution(cacheSize, cities):
answer = 0
from collections import deque
cache = deque([])
for city in cities:
city = city.lower()
if city in cache:
cache.remove(city)
cache.append(city)
answer += 1
else:
if len(cache) < cacheSize:
cache.append(city)
elif cacheSize != 0:
cache.popleft()
cache.append(city)
answer += 5
return answer
def solution(n, left, right):
return [max(i//n, i%n)+1 for i in range(left, right+1)]
시간 초과 풀이
def solution(n, left, right):
answer = []
# n * n 행렬
graph = [[1] * n for _ in range(n)]
for i in range(2, n+1):
for j in range(i):
graph[i-1][j] = i
graph[j][i-1] = i
temp = []
for idx, g in enumerate(graph):
temp.extend(g)
return temp[left:right+1]
괄호 회전하기 링크
풀이 : stack, deque 활용