566. Reshape the Matrix

public class Solution {
    public int[][] matrixReshape(int[][] nums, int r, int c) {
        ArrayList li=new ArrayList();
        int i=0,j=0,count=0;
        if((nums.length*nums[0].length)!=(r*c))return nums;
        for(;i

太蠢了,人家只用一次循环就搞定了。

public class Solution {
    public int[][] matrixReshape(int[][] nums, int r, int c) {
      
        int row = nums.length;
        int col = nums[0].length;
        int [][] result = new int[r][c];
        
        if (r*c!=row*col){
            return nums;
        }
        int n=0, m=0;
        for (int i=0; i

你可能感兴趣的:(566. Reshape the Matrix)