Leetcode 867. Transmission Matrix

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 }

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5243 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.