diff --git a/Spiral Matrix.cpp b/Spiral Matrix.cpp index 432807b..d56cc19 100644 --- a/Spiral Matrix.cpp +++ b/Spiral Matrix.cpp @@ -1,43 +1,50 @@ -lass Solution{ - - public: - int findK(vector> &matrix, int n, int m, int k) - { - // Your code goes here - int temp=m; - m=n; - n=temp; +class Solution { +public: + vector spiralOrder(vector>& matrix) { - int r=0; - int c=0; - int count=0; - vectorans(m*n); + vectorvar; + int row=matrix.size(); + int col=matrix[0].size(); - while(r=c;i--){ - ans[count++]=matrix[m-1][i]; - } - m--; + ending_col--; + //ending_row + for(int i=ending_col;count=starting_col;i--) + { + var.push_back(matrix[ending_row][i]); + count++; } - if(c=r;i--){ - ans[count++]=matrix[i][c]; - } - c++; - } + ending_row--; + //staring col + for(int i=ending_row;count=starting_row;i--) + { + var.push_back(matrix[i][starting_col]); + count++; + } + starting_col++; } - - return ans[k-1]; + return var; } - -}; \ No newline at end of file +};