Skip to content

Commit 5b17789

Browse files
Added Array Problem-Solution
Co-authored-by: Ashish Kumar Singh <[email protected]> Co-authored-by: Laxman Singh Koranga <[email protected]>
1 parent 164a647 commit 5b17789

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Java/Array/TransposeMatrix.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* PROBLEM: 867 : Transpose Matrix
3+
*/
4+
public class TransposeMatrix {
5+
public static int[][] transpose(int[][] matrix) {
6+
// rows in the matrix.
7+
int rows = matrix.length;
8+
// columns in the matrix.
9+
int columns = matrix[0].length;
10+
// result matrix will store the transpose of the given matrix.
11+
int[][] output = new int[columns][rows];
12+
13+
for (int i = 0; i < rows; i++) {
14+
for (int j = 0; j < columns; j++) {
15+
output[j][i] = matrix[i][j];
16+
}
17+
}
18+
return output;
19+
}
20+
}

0 commit comments

Comments
 (0)