package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/transpose-matrix/
 */
public class Problem868 {
    public int[][] transpose(int[][] A) {
        int nRow = A.length;
        int nCol = 0;
        if (A.length > 0) {
            nCol = A[0].length;
        }
        int[][] result = new int[nCol][nRow];
        for (int row = 0; row < nRow; row++) {
            for (int col = 0; col < nCol; col++) {
                result[col][row] = A[row][col];
            }
        }
        return result;
    }

    private static void print(int[][] matrix) {
        for (int[] array : matrix) {
            System.out.println(Arrays.toString(array));
        }
        System.out.println();
    }
    public static void main(String[] args) {
        Problem868 prob = new Problem868();
        // [1, 4, 7],
        // [2, 5, 8],
        // [3, 6, 9]
        print(prob.transpose(new int[][]{
            {1, 2, 3},
            {4, 5, 6},
            {7, 8, 9}
        }));
        // [1, 4],
        // [2, 5],
        // [3, 6]
        print(prob.transpose(new int[][]{
            {1, 2, 3},
            {4, 5, 6}
        }));
    }
}

@@ -723,445 +723,6 @@
   %7D%0A
-    public static void main(String%5B%5D args) %7B%0A        Problem868 prob = new Problem868();%0A        // %5B1, 4, 7%5D,%0A        // %5B2, 5, 8%5D,%0A        // %5B3, 6, 9%5D%0A        print(prob.transpose(new int%5B%5D%5B%5D%7B%0A            %7B1, 2, 3%7D,%0A            %7B4, 5, 6%7D,%0A            %7B7, 8, 9%7D%0A        %7D));%0A        // %5B1, 4%5D,%0A        // %5B2, 5%5D,%0A        // %5B3, 6%5D%0A        print(prob.transpose(new int%5B%5D%5B%5D%7B%0A            %7B1, 2, 3%7D,%0A            %7B4, 5, 6%7D%0A        %7D));%0A    %7D%0A
 %7D%0A

Update problem 868