-
삼각 달팽이코딩 테스트/Level 2 2020. 10. 22. 00:10반응형
삼각 달팽이
월간 코드 챌린지 시즌1
413명 완료https://programmers.co.kr/learn/courses/30/lessons/68645
Python
def solution(n): triangle = [[0] * i for i in range(1, n + 1)] phase = [(1, 0), (0, 1), (-1, -1)] phase_index = x = y = 0 count = 1 for i in range(n, 0, -1): for j in range(i, 0, -1): if j == 1: phase_index = (phase_index + 1) % 3 triangle[x][y] = count x, y = x + phase[phase_index][0], y + phase[phase_index][1] count += 1 return [each for column in triangle for each in column]
깔끔하자~!
반응형