Skip to main content

48. Rotate Image

分析

一图胜千言

Pasted image 20220415212714.png 做这道题之前先看下 867. Transpose Matrix

题解

func rotate(matrix [][]int)  {
n := len(matrix)
// 对角线
for i := 0; i < n; i++ {
for j := i + 1; j < n; j++ {
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
}
}

// 90%
for i := 0; i < n; i++ {
for j := 0; j < n / 2; j++ {
matrix[i][j], matrix[i][n - j - 1] = matrix[i][n - j - 1], matrix[i][j]
}
}
}