-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotate_Image.java
35 lines (32 loc) · 936 Bytes
/
Rotate_Image.java
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
29
30
31
32
33
34
35
class Solution {
public void rotate(int[][] matrix) {
Rotate(matrix);
}
public static void Tranpose(int[][] arr){
for(int i=0;i<arr.length;i++){
for(int j=i+1;j<arr.length;j++){
int temp = arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i] = temp;
// System.out.print(arr+" ");
}
}
}
public static void Rotate(int [][]arr){
Tranpose(arr);
for(int i=0;i<arr.length;i++){
reverse(arr[i]);
}
}
public static void reverse(int []arr){
int i=0;
int j=arr.length-1;
while(i<j){
int temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
i++;
j-- ;
}
}
}