def solution(n):
answer = []
g = [[0] * i for i in range(1, n+1)]
x = y= 0
s = 1
turn = 0
direction = [[1,0], [0,1], [-1,-1]]
while turn < n:
d = direction[turn % 3]
if x + d[0] < n and y + d[1] < n and g[x+d[0]][y+d[1]] == 0:
g[x][y] = s
s+= 1
x, y = x+ d[0], y +d[1]
else:
turn += 1
if turn == n:
g[x][y] = s
# s+= 1
for i in g:
answer += i
return answer
단순 구현 문제