python 使用恒定空间,将2d阵列向右旋转90度
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用恒定空间,将2d阵列向右旋转90度相关的知识,希望对你有一定的参考价值。
def rotateSquare(a, start, length):
lastIndex = start + length - 1
for i in range(length-1):
temp = a[start][start + i]
a[start][start + i] = a[lastIndex - i][start]
a[lastIndex - i][start] = a[lastIndex][lastIndex - i]
a[lastIndex][lastIndex - i] = a[start + i][lastIndex]
a[start + i][lastIndex] = temp
# Rotate right a 2D array by 90 degrees
def rotate2DArray(a):
i = 0
squareLength = len(a)
while True:
rotateSquare(a, i, squareLength)
i += 1
squareLength -= 2
if squareLength < 2:
break
以上是关于python 使用恒定空间,将2d阵列向右旋转90度的主要内容,如果未能解决你的问题,请参考以下文章