标签:ret tps int problems i++ cto ref class turn
https://leetcode-cn.com/problems/diagonal-traverse/
vector<int> nums;
int m = matrix.size();
int n = matrix[0].size();
int i = 0;
while (i < m + n)
{
int x1 = (i < m) ? i : m - 1;
int y1 = i - x1;
while (x1 >= 0 && y1 < n)
{
nums.push_back(matrix[x1][y1]);
x1--;
y1++;
}
i++;
if (i >= m + n) break;
int y2 = (i < n) ? i : n - 1;
int x2 = i - y2;
while (y2 >= 0 && x2 < m)
{
nums.push_back(matrix[x2][y2]);
x2++;
y2--;
}
i++;
}
return nums;
标签:ret tps int problems i++ cto ref class turn
原文地址:https://www.cnblogs.com/Hunter01/p/12534903.html