-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathRotateMatrix.java
More file actions
41 lines (34 loc) · 984 Bytes
/
RotateMatrix.java
File metadata and controls
41 lines (34 loc) · 984 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
29
30
31
32
33
34
35
36
37
38
39
40
41
package Array;
import java.util.ArrayList;
/**
* Author - archit.s
* Date - 01/09/18
* Time - 5:28 PM
*/
public class RotateMatrix {
public void rotate(ArrayList<ArrayList<Integer>> a) {
int up =0 , down = a.size()-1;
int left = 0, right = down;
if(down<=0){
return ;
}
while(up<down && left<right){
int j=0;
while((up+j)<down){
int topLeft = a.get(up).get(left+j);
int topRight = a.get(up+j).get(right);
int bottomLeft = a.get(down-j).get(left);
int bottomRight = a.get(down).get(right-j);
a.get(up).set(left+j, bottomLeft);
a.get(up+j).set(right, topLeft);
a.get(down).set(right-j, topRight);
a.get(down-j).set(left, bottomRight);
j++;
}
up++;
down--;
left++;
right--;
}
}
}