From 70db6f8f56e2860ed7a45afde1c6ac4d15e9f4f4 Mon Sep 17 00:00:00 2001 From: Chirag <90318064+Chiragsharma2@users.noreply.github.com> Date: Sun, 9 Oct 2022 16:31:03 +0530 Subject: [PATCH] Spiral Matrix Solution Spiral Matrix Problem solved in C++ Programming language. A medium - level LEETCODE problem solved. --- Spiral Matrix/Spiral Matrix Solution | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Spiral Matrix/Spiral Matrix Solution 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; + } +};