首页 > 代码库 > Leetcode566. Reshape the Matrix

Leetcode566. Reshape the Matrix

	public int[][] func(int[][] nums,int r,int c){
		int m=nums.length;
		int k=0;
		int n=nums[0].length;
		  if(r*c!=m*n){
			return nums;
		}
		  int[][] res = new int[r][c];
		  for(int i=0;i<r;i++){
			  for(int j=0;j<c;j++,k++){
				  res[i][j]=nums[k/n][k%n];
			  }
		  }
		  return res;
		  
	}

 

Leetcode566. Reshape the Matrix