Given a matrixA, return the transpose ofA.

The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix.

一道过分简单的题,如果面到了,也许说明对面准备直接挂你,就不用继续

class Solution {
    public int[][] transpose(int[][] A) {
        int m = A.length;
        int n = A[0].length;

        int[][] res = new int[n][m];

        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                res[j][i] = A[i][j];
            }
        }

        return res;
    }
}

results matching ""

    No results matching ""