Shorter code of Anti diagonal


#1
vector<vector<int> > Solution::diagonal(vector<vector<int> > &A) {
    
    int i=0,j=0,start_row,start_col;
    int n=A.size();
    vector<vector<int> > v;
    for(int diag=1;diag<2*n;diag++)
    {
        vector<int> temp;
        for(start_row=i,start_col=j;start_row<n && start_col>=0; start_row++,start_col--)
        {
            temp.push_back(A[start_row][start_col]);
        }
        v.push_back(temp);
        if(j+1==n) i++;
        else j++;
    }
    return v;
}

#2

vector<vector > Solution::diagonal(vector<vector > &A) {
int x=A.size();
vector<vector >res(2*x-1);
int count=0;
for(int i=0;i<x;i++){
int a=0,y=i;
while(a<x&&y>=0){
res[count].push_back(A[a][y]);
a++;
y–;
}
count++;
}
for(int i=1;i<x;i++){
int a=i,y=x-1;
while(a<x&&y>=0){
res[count].push_back(A[a][y]);
a++;
y–;
}
count++;
}
return res;
}