Skip to content

Commit 7028b0e

Browse files
solves transpose matrix
1 parent 0d51a1e commit 7028b0e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
| 852 | [Peak Index in Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array) | [![Java](assets/java.png)](src/PeakIndexInMountainArray.java) |
233233
| 859 | [Buddy Strings](https://leetcode.com/problems/buddy-strings) | [![Java](assets/java.png)](src/BuddyStrings.java) |
234234
| 860 | [Lemonade Change](https://leetcode.com/problems/lemonade-change) | [![Java](assets/java.png)](src/LemonadeChange.java) |
235-
| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | |
235+
| 867 | [Transpose Matrix](https://leetcode.com/problems/transpose-matrix) | [![Java](assets/java.png)](src/TransposeMatrix.java) |
236236
| 868 | [Binary Gap](https://leetcode.com/problems/binary-gap) | |
237237
| 872 | [Leaf-Similar Trees](https://leetcode.com/problems/leaf-similar-trees) | |
238238
| 874 | [Walking Robot Simulation](https://leetcode.com/problems/walking-robot-simulation) | |

src/TransposeMatrix.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class TransposeMatrix {
2+
public int[][] transpose(int[][] matrix) {
3+
final int rows = matrix.length, columns = matrix[0].length;
4+
final int[][] result = new int[columns][rows];
5+
6+
for (int row = 0 ; row < rows ; row++) {
7+
for (int column = 0 ; column < columns ; column++) {
8+
result[column][row] = matrix[row][column];
9+
}
10+
}
11+
12+
return result;
13+
}
14+
}

0 commit comments

Comments
 (0)