-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP566.cpp
More file actions
31 lines (28 loc) · 742 Bytes
/
P566.cpp
File metadata and controls
31 lines (28 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "header.h"
#include <vector>
class Solution {
public:
vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
int _r, _c;
_r = nums.size();
if (nums.empty()) return nums;
if (nums.front().empty()) return nums;
_c = nums.front().size();
if (_r *_c != r*c) return nums;
vector<vector<int>> ret;
ret.resize(r);
for (auto &row:ret) row.resize(c);
for (int i=0; i<_r; i++) {
for (int j=0; j<_c; j++) {
int _i,_j;
_i = (i*_c+j)/c;
_j = (i*_c+j)%c;
ret[_i][_j] = nums[i][j];
}
}
return ret;
}
};
int main() {
return 0;
}