Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit de151ed

Browse files
author
Ram swaroop
committed
matrix rotation : comments added
1 parent 6344e34 commit de151ed

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/me/ramswaroop/arrays/RotateMatrixBy90Degrees.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
*/
1010
public class RotateMatrixBy90Degrees {
1111

12+
/**
13+
* Rotates a 2-D array by 90 degrees clockwise.
14+
* <p/>
15+
* The algorithm is simple:
16+
* 1st row = last column
17+
* 2nd row = 2nd last column
18+
* and so on...
19+
*
20+
* @param a
21+
* @return
22+
*/
1223
public static int[][] rotateMatrixBy90DegreesRight(int[][] a) {
1324
int rows = a.length, columns = a[0].length;
1425
int[][] rotatedMatrix = new int[columns][rows];
@@ -36,9 +47,9 @@ public static void main(String a[]) {
3647
print2DMatrix(ar);
3748
System.out.println("--------");
3849
print2DMatrix(rotateMatrixBy90DegreesRight(ar));
39-
50+
4051
System.out.println("========");
41-
52+
4253
ar = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 5, 7}};
4354
print2DMatrix(ar);
4455
System.out.println("--------");

0 commit comments

Comments
 (0)