Sunday, September 3, 2017

Leetcode 54: Spiral Matrix

Sept. 3, 2017


It is the classical medium level algorithm to write spiral matrix in one dimensional array. I have practiced more than 3 times. The key idea is to go over the four iterations from top row, last column, last row and first column, edge cases are one row or one column. last row and first column is optional because they are handled only if there are more than one row or more than two columns.

Compared to the practice in March of 2016, I am so happy to see that I can write more readable code.

Algorithm practice 

C# code is here


No comments:

Post a Comment