forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1329.cpp
More file actions
25 lines (24 loc) · 698 Bytes
/
1329.cpp
File metadata and controls
25 lines (24 loc) · 698 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
class Solution
{
public:
vector<vector<int>> diagonalSort(vector<vector<int>>& mat)
{
int r = mat.size(), c = mat[0].size();
int t[min(r, c)] = {0};
for (int i = 0; i < r; i++)
{
int k = min(r - i, c);
for (int j = 0; j < k; j++) t[j] = mat[i + j][j];
sort(t, t + k);
for (int j = 0; j < k; j++) mat[i + j][j] = t[j];
}
for (int i = 1; i < c; i++)
{
int k = min(c - i, r);
for (int j = 0; j < k; j++) t[j] = mat[j][i + j];
sort(t, t + k);
for (int j = 0; j < k; j++) mat[j][i + j] = t[j];
}
return mat;
}
};