原题链接:Leecode 498. 对角线遍历
class Solution {
public:
vector<int> findDiagonalOrder(vector<vector<int>>& mat) {
vector<int> res;
int m=mat.size(),n=mat[0].size();
int i=0,j=0,sum=m*n,t=0;
while(sum--)
{
res.push_back(mat[i][j]);
if(t==0)
{
if(j==n-1) { i++; t=1; continue;}
else if(i==0) { j++; t=1; continue;}
i--;j++;
}
else if(t==1)
{
if(i==m-1) { j++; t=0; continue;}
else if(j==0) { i++; t=0; continue;}
i++;j--;
}
}
return res;
}
};