## 在Java中如何旋转NxN矩阵？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (52)

``````public static void rotate(int[][] matrix, int n) {
for (int layer = 0; layer < n / 2; ++layer) {
int first = layer;
int last = n - 1 - layer;
for(int i = first; i < last; ++i) {
int offset = i - first;
int top = matrix[first][i]; // save top

// left -> top
matrix[first][i] = matrix[last-offset][first];

// bottom -> left
matrix[last-offset][first] = matrix[last][last - offset];

// right -> bottom
matrix[last][last - offset] = matrix[i][last];

// top -> right
matrix[i][last] = top; // right <- saved top
}
}
}
``````

```  public static void rotateInPlace90DegreesClockwise(int[][] matrix) {
int n = matrix.length;
int half = n / 2;

for (int layer = 0; layer < half; layer++) {
int first = layer;
int last = n - 1 - layer;

for (int i = first; i < last; i++) {
int offset = i - first;
int j = last - offset;
int top = matrix[first][i]; // save top

// left -> top
matrix[first][i] = matrix[j][first];

// bottom -> left
matrix[j][first] = matrix[last][j];

// right -> bottom
matrix[last][j] = matrix[i][last];

// top -> right
matrix[i][last] = top; // right <- saved top
}
}
}```

Tina

Go Serverless!

### 域名在腾讯备的案，解析的腾讯云，现在想把域名解析到别商家的服务器，腾讯云会把备案注销吗？

software微软、谷歌、腾讯、阿里、百度……

Hyman Wang

Jinqn