Subject link: https://leetcode-cn.com/problems/transpose-matrix/
Given a matrix A, return the transpose matrix of A.
The transposition of a matrix refers to flipping the main diagonal of the matrix and exchanging the row index and column index of the matrix.
Example 1:
Input: [[1,2,3],[4,5,6],[7,8,9] ]
Output: [[1,4,7],[2,5,8],[3,6,9]]
Example 2:
Input: [[1, 2,3],[4,5,6]]
Output: [[1,4],[2,5],[3,6]]
Reminder:< /p>
1 <= A.length<= 1000
1 <= A[0].length<= 1000
1 class Solution {
2 public int[][] transpose(int[][] A) {
3 int[][] newA=new int[A[0]. length][A.length];
4 for(int i=0;i){
5 for(int j=0;j){
6 newA[j][i]=A[i][ j];
7 }
8 }
9 return newA;
10 }
11 }
1 class Solution {
2 public int[][] transpose(int[][] A) {
3 int[][] newA=new int[A[0]. length][A.length];
4 for(int i=0;i){
5 for(int j=0;j){
6 newA[j][i]=A[i][ j];
7 }
8 }
9 return newA;
10 }
11 }