566.重塑矩阵
做出来了,说不难也有一点点难,因为要找那个行列的关系,有点找规律的意思。
class Solution {
public int[][] matrixReshape(int[][] mat, int r, int c) {
int [][]a=new int[r][c];
int row=mat.length,col=mat[0].length,count=0;
if(row*col!=r*c)
return mat;
for(int i=0;i
|
for(int j=0;j
a[count/c][count%c]=mat[i][j];
count++;
}
return a;
}
}
303.区域和检索-数组不可变
没太理解,不会,但不难。
class NumArray {
int []sums;public NumArray(int[] nums) {
int n=nums.length;
sums=new int[n];
sums[0]=nums[0];
for(int i=1;i
sums[i]=nums[i]+sums[i-1];
}}
public int sumRange(int left, int right) {
if(left>=1)
return sums[right]-sums[left-1];
else
return sums[right];}
}/**
* Your NumArray object will be instantiated and called as such:
* NumArray obj = new NumArray(nums);
* int param_1 = obj.sumRange(left,right);
*/