Shortest C++ Solution || O(n*n)


#1
vector<vector<int> > Solution::diagonal(vector<vector<int> > &A) {
    vector<vector<int>>res;
    for(int i=0;i<A[0].size();i++){
        int j=0,k=i;
        vector<int>temp;
        while(j<A.size() && k>=0)
        temp.push_back(A[j++][k--]);
        res.push_back(temp);
    }
    for(int i=1;i<A.size();i++){
        int j=i,k=A[0].size()-1;
        vector<int>temp;
        while(j<A.size() && k>=0)
        temp.push_back(A[j++][k--]);
        res.push_back(temp);
    }
    return res;
}