import copy
class Solution:
def rotate(self, matrix: [[int]]) -> None:
cmatrix = copy.deepcopy(matrix)
mlen = len(matrix)
for i in range(mlen // 2):
curr_len = mlen - i * 2
for j in range(curr_len - 1):
ii, jj = i, i + j
iii, jjj = i + j,i + curr_len - 1
matrix[iii][jjj] = cmatrix[ii][jj]
ii, jj = iii, jjj
iii, jjj = i + curr_len - 1,i + curr_len - 1 - j
matrix[iii][jjj] = cmatrix[ii][jj]
ii, jj = iii, jjj
iii, jjj = i + curr_len - 1 - j, i
matrix[iii][jjj] = cmatrix[ii][jj]
ii, jj = iii, jjj
iii, jjj = i, i + j
matrix[iii][jjj] = cmatrix[ii][jj]
【leetcode|LeetCode 48. Rotate Image 时间复杂度(O(n))】
推荐阅读
- LeetCode|LeetCode 53. Maximum Subarray 时间复杂度(O(n))
- LeetCode 45. Jump Game II 时间复杂度(O(n))
- LeetCode 55. Jump Game 时间复杂度(O(n))
- LeetCode|LeetCode 42. Trapping Rain Water 时间复杂度(O(n))
- leetcode|算法入门之字符串(Python)【初级算法——字符串】【蓝桥杯练习】【力扣练习】
- 备战蓝桥杯|蓝桥杯python组十一届省赛真题+解析+代码(通俗易懂版)
- 备战蓝桥杯|2020年第十一届蓝桥杯省赛Python组(真题+解析+代码)(作物杂交)
- 备战蓝桥杯|2021年第十二届蓝桥杯省赛Python组(真题+解析+代码)(直线)
- 备战蓝桥杯|2021年第十二届蓝桥杯省赛Python组(真题+解析+代码)(时间显示)