-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotateArr.java
32 lines (32 loc) · 878 Bytes
/
rotateArr.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
class Solution {
public void rotate(int[][] matrix) {
//Transpose
for(int j = 0;j<matrix.length;j++)
{
for(int i=j;i<matrix[0].length;i++)
{
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
int first, last;
for(int arr[] : matrix)
{ first = 0;last = arr.length - 1;
while(first <= last)
{
int temp = arr[first];
arr[first] = arr[last];
arr[last] = temp;
first++;last--;
}
}
}
}
// }
// public void swap(int[][] matrix, int a1, int a2, int b1, int b2)
// {
// int temp = matrix[a1][a2];
// matrix[a1][a2] = matrix[b1][b2];
// matrix[b1][b2] = temp;
// }