diff --git a/Spiral Matrix/Spiral Matrix Solution b/Spiral Matrix/Spiral Matrix Solution new file mode 100644 index 0000000..7ce7890 --- /dev/null +++ b/Spiral Matrix/Spiral Matrix Solution @@ -0,0 +1,44 @@ +lass Solution { +public: + vector spiralOrder(vector>& matrix) { + int row = matrix.size(); + int col = matrix[0].size(); + + vector ans; + + int count = 0; + int total = row*col; + + int starting_row = 0; + int starting_col = 0; + int ending_row = row-1; + int ending_col = col-1; + + while(count=starting_col; index--){ + ans.push_back(matrix[ending_row][index]); + count++; + } + ending_row--; + + for(int index = ending_row; count=starting_row; index--){ + ans.push_back(matrix[index][starting_col]); + count++; + } + starting_col++; + } + return ans; + } +};