|
1 | 1 | ---
|
2 | 2 | id: spiral-matrix
|
3 | 3 | title: Spiral Matrix
|
4 |
| -sidebar_label: 0054 Spiral Matrix |
| 4 | +sidebar_label: 0054-Spiral-Matrix |
5 | 5 | tags:
|
6 | 6 | - Array
|
7 | 7 | - Matrix
|
@@ -69,9 +69,7 @@ We continue this process while adjusting the boundaries until all elements have
|
69 | 69 |
|
70 | 70 | ### Code in Different Languages
|
71 | 71 |
|
72 |
| -<Tabs> |
73 |
| -<TabItem value="cpp" label="C++"> |
74 |
| - <SolutionAuthor name="@Vipullakum007"/> |
| 72 | +### C++ Solution |
75 | 73 |
|
76 | 74 | ```cpp
|
77 | 75 |
|
@@ -133,8 +131,8 @@ int main() {
|
133 | 131 | }
|
134 | 132 | </TabItem>
|
135 | 133 | ```
|
136 |
| -### JAVA |
137 |
| -```<TabItem value="java" label="Java"> <SolutionAuthor name="@Vipullakum007"/> |
| 134 | +### JAVA Solution |
| 135 | +```java |
138 | 136 | import java.util.ArrayList;
|
139 | 137 | import java.util.List;
|
140 | 138 |
|
@@ -185,11 +183,11 @@ public class SpiralMatrix {
|
185 | 183 | System.out.println(sm.spiralOrder(matrix)); // Output: [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7]
|
186 | 184 | }
|
187 | 185 | }
|
188 |
| -</TabItem> |
| 186 | +
|
189 | 187 | ```
|
190 |
| -### Python |
| 188 | +### Python Solution |
191 | 189 |
|
192 |
| -```<TabItem value="python" label="Python"><SolutionAuthor name="@Vipullakum007"/> |
| 190 | +```python |
193 | 191 | def spiralOrder(matrix):
|
194 | 192 | if not matrix:
|
195 | 193 | return []
|
@@ -230,20 +228,15 @@ matrix = [
|
230 | 228 | ]
|
231 | 229 | print(spiralOrder(matrix)) # Output: [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7]
|
232 | 230 |
|
233 |
| -</TabItem> |
234 | 231 | ```
|
235 |
| -</Tabs> |
236 | 232 |
|
237 | 233 | ### Complexity Analysis
|
238 | 234 | #### Time Complexity: O(m * n)
|
239 |
| -**Reason:** We visit every element in the matrix exactly once. |
| 235 | +>Reason: We visit every element in the matrix exactly once. |
240 | 236 |
|
241 | 237 | **Space Complexity:** O(1)
|
242 |
| -**Reason:** We only use a fixed amount of extra space, regardless of the input size. |
| 238 | +>Reason: We only use a fixed amount of extra space, regardless of the input size. |
243 | 239 | ### References
|
244 | 240 | **LeetCode Problem:** Spiral Matrix
|
245 | 241 |
|
246 |
| -**Author's LeetCode Profile:** Vipul Lakum |
247 |
| -``` |
248 |
| -
|
249 | 242 |
|
0 commit comments