• 문제 링크
Transpose Matrix - LeetCode
Can you solve this real interview question? Transpose Matrix - Given a 2D integer array matrix, return the transpose of matrix. The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices. [https://
leetcode.com
• 풀이 코드
public class Solution {
public int[][] transpose(int[][] matrix) {
int[][] trans = new int[matrix[0].length][matrix.length];
for (int i = 0; i < matrix[0].length; i++) for (int j = 0; j < matrix.length; j++) trans[i][j] = matrix[j][i];
return trans;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 872. Leaf-Similar Trees - Java (0) | 2026.10.30 |
|---|---|
| [LeetCode] 868. Binary Gap - Java (0) | 2026.10.29 |
| [LeetCode] 860. Lemonade Change - Java (0) | 2026.10.27 |
| [LeetCode] 859. Buddy Strings - Java (0) | 2026.10.26 |
| [LeetCode] 844. Backspace String Compare - Java (0) | 2026.10.25 |
댓글