@@ -0,0 +1,1214 @@
+/**%0A * You're given a matrix represented by a two-dimensional array, and two positive integers r and c representing the row number and column number of the wanted reshaped matrix, respectively.%0A * The reshaped matrix need to be filled with all the elements of the original matrix in the same row-traversing order as they were.%0A * If the 'reshape' operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.%0A *%0A * Complexity: O(N * M) runtime and O(R * C) space where N and M are the length and height of the orignal array and R and C are the length and height of the new array.%0A */%0Apublic class Solution %7B%0A  public int%5B%5D%5B%5D matrixReshape(int%5B%5D%5B%5D nums, int r, int c) %7B%0A    // No possible way to reshape.%0A    if (nums.length == 0 %7C%7C nums%5B0%5D.length == 0) return nums;%0A    if (r * c != nums.length * nums%5B0%5D.length) return nums;%0A%0A    int%5B%5D%5B%5D arr = new int%5Br%5D%5Bc%5D;%0A    int x = 0;%0A    int y = 0;%0A%0A    for (int i = 0; i %3C r; i ++) %7B%0A      for (int j = 0; j %3C c; j ++) %7B%0A        arr%5Bi%5D%5Bj%5D = nums%5Bx%5D%5By%5D;%0A%0A        if (y %3C nums%5B0%5D.length) y ++;%0A%0A        if (y %3E= nums%5B0%5D.length) %7B%0A          y = 0;%0A          x ++;%0A        %7D%0A      %7D%0A    %7D%0A%0A    return arr;%0A  %7D%0A%7D%0A

Add 566