-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnti Diagonals.cpp
More file actions
41 lines (32 loc) · 845 Bytes
/
Anti Diagonals.cpp
File metadata and controls
41 lines (32 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
vector<vector<int> > Solution::diagonal(vector<vector<int> > &arr) {
int rows=arr.size();
int cols=arr.size();
vector<vector<int>>ans;
for(int i=0;i<cols;i++)
{
vector<int>small ;
int j=0 ;
int k=i;
while(j<rows&&k>=0)
{
small.push_back(arr[j][k]) ;
j++ ;
k-- ;
}
ans.push_back(small) ;
}
for(int i=1;i<rows;i++)
{
vector<int>small;
int k=cols-1 ;
int j=i ;
while(j<rows&&k>=0)
{
small.push_back(arr[j][k]) ;
j++ ;
k-- ;
}
ans.push_back(small) ;
}
return ans ;
}