コード例 #1
0
def spiralOrder(matrix):
    if not matrix:
        return []

    return [
        matrix[y][x]
        for x, y in spiral(True, 0, 0, len(matrix[0]), len(matrix))]
コード例 #2
0
def generateMatrix(n):
    matrix = [[0 for _ in range(n)] for _ in range(n)]

    for (x, y), v in zip(spiral(True, 0, 0, n, n), count(1)):
        matrix[y][x] = v

    return matrix
コード例 #3
0
def generateMatrix(n):
    matrix = [[0 for _ in xrange(n)] for _ in xrange(n)]

    for (x, y), v in izip(spiral(True, 0, 0, n, n), count(1)):
        matrix[y][x] = v

    return matrix
コード例 #4
0
def spiralOrder(matrix):
    if not matrix:
        return []

    return [
        matrix[y][x]
        for x, y in spiral(True, 0, 0, len(matrix[0]), len(matrix))
    ]