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;

	}
时间: 2024-10-28 10:17:16

Leetcode566. Reshape the Matrix的相关文章

LeetCode 566. Reshape the Matrix (重塑矩阵)

In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. You're given a matrix represented by a two-dimensional array, and two positive integers r and c rep

leetcode算法:Reshape the Matrix

In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. You're given a matrix represented by a two-dimensional array, and two positive integers r and c rep

[LeetCode] Reshape the Matrix 矩阵重塑

In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. You're given a matrix represented by a two-dimensional array, and two positive integers r and c rep

LeetCode - 566. Reshape the Matrix

In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. You're given a matrix represented by a two-dimensional array, and two positive integers r and c rep

(leetcode题解)Reshape the Matrix

In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. You're given a matrix represented by a two-dimensional array, and two positive integers r and c rep

[LeetCode] Reshape the Matrix

In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. You're given a matrix represented by a two-dimensional array, and two positive integers r and c rep

566. Reshape the Matrix

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Helvetica Neue"; color: #323333 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #323333; background-color: #f5f5f5 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px

566. Reshape the Matrix矩阵重排

[抄题]: In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. You're given a matrix represented by a two-dimensional array, and two positive integers r and

566. Reshape the Matrix - LeetCode

Question 566. Reshape the Matrix Solution 题目大意:给一个二维数组,将这个二维数组转换为r行c列 思路:构造一个r行c列的二维数组,遍历给出二给数组nums,合理转换原数组和目标数组的行列转换. Java实现: public int[][] matrixReshape(int[][] nums, int r, int c) { int originalR = nums.length; int originalC = nums[0].length; if