void getIn(int i, int n, int &x, int &y, int&mn)
{
if (i < n)
{x = i; y = 0; mn = x + 1;}
else
{x = n - 1; y = i - n + 1; mn = n - y;}
}
vector<vector<int> > Solution::diagonal(vector<vector<int> > &A) {
vector<vector<int> > tot{};
vector<int> tmp;
int x, y, mn;
for (int i = 0; i < A.size() * 2 - 1; i++)
{
getIn(i, A.size(), x, y, mn);
tmp = vector<int>();
for (int j = 0; j < mn; j++)
tmp.push_back(A[y + j][x - j]);
tot.push_back(tmp);
}
return tot;
}
C++ O(N^2) the way you read it
ami-now
#1