Linkage
https://leetcode.com/problems/spiral-matrix/description/
Easy to implement the alogithm, but pay attention to the bounds.
1 | class Solution { |
Follow up
https://leetcode.com/problems/spiral-matrix-ii/description/
Code
In this problem, we found the fact that the direction change is regular, namely, it follows right, down, left, up, right, down, left, up. So we can simplify the code from switch case to simple loop.This polishment also add the speed of calculation compared to the switch way.
1 | class Solution { |