Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def spiral_copy(inputMatrix):
- rowEnd = len(inputMatrix)
- colEnd = len(inputMatrix[0])
- rowStart = 0
- colStart = 0
- result = []
- while (rowStart < rowEnd and colStart < colEnd):
- for i in range(colStart, colEnd):
- result.append(inputMatrix[rowStart][i])
- rowStart+=1
- for i in range(rowStart, rowEnd):
- result.append(inputMatrix[i][colEnd - 1])
- colEnd-=1
- if (rowStart < rowEnd):
- for i in range(colEnd - 1, colStart - 1, -1):
- result.append(inputMatrix[rowEnd - 1][i])
- rowEnd-=1
- if (colStart < colEnd):
- for i in range(rowEnd - 1, rowStart - 1, -1):
- result.append(inputMatrix[i][colStart])
- colStart+=1
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement