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;
		  
	}

 

posted @ 2017-04-30 15:21  vector11248  阅读(151)  评论(0编辑  收藏  举报