Spiral Matrix III
https://leetcode.com/problems/spiral-matrix-iii/description/
Last updated
Was this helpful?
https://leetcode.com/problems/spiral-matrix-iii/description/
Last updated
Was this helpful?
可越界旋转矩阵,按旋转顺序记录所有落在界内把格子的值。因为可越界,边界收缩规律不再明显,因此模拟走格。经观察,会向右和和向下走k步,然后左和上k + 1步,再右和下k+2步。。即会在两个方向走同一步数次,然后步数再加一。
Time Complexity: O((\max(R, C))^2)O((max(R,C))
2
). Potentially, our walk needs to spiral until we move R in one direction, and CC in another direction, so as to reach every cell of the grid.
1 + 1 + 2 + 2 + 3 + ... + max(R/C) = O(max(R, C)^2)