Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
Spiral Problem Solution: class Solution(object): def spiralOrder(self, matrix): return matrix and [*matrix.pop(0)] + self.spiralOrder([*zip(*matrix)][::-1]) #[[123][456][789]] -> [] """ explaination: the 'matrix and' makes sure the matric is not empty matrix.pop(0) removes ther first row (we want to add it back in the next step) [*matric.pop(0)] it makes an array without the first row (* in python turns an iterable into its constitutents) zip(*matrix)it splits the matrix into its rows and then combines them together in dfifrent order [::-1] reverses the amtric 'self.spiralOrder' does keeps on doing it until there are no more elements in the list the + before the self.spiralorder adds back the first row. Like if it is [6,9,8,7,4,5], then it will add back the [1,2,3] to it the 'matric and [*matrix.pop(0)]' makes sure that after removing a row, the matrix isnt empty """
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)