forked from noisefilter19/LeetCode_Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path48_RotateImage.java
More file actions
28 lines (22 loc) · 842 Bytes
/
48_RotateImage.java
File metadata and controls
28 lines (22 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
link: https://leetcode.com/problems/rotate-image/
class Solution {
public void rotate(int[][] matrix) {
int n=matrix.length;
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[layer][i];
//left -> top
matrix[layer][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;
}
}
}
}