본문 바로가기
Problem Solving/LeetCode

[LeetCode] 867. Transpose Matrix - Java

by graycode 2026. 10. 28.

• 문제 링크

 

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;
    }

}

댓글