You are given a matrix whose elements are initially set to 0 and a starting position (startRow, startCol) (0-based indexing).
Fill the matrix with increasing integers starting from 1 in a clockwise spiral pattern, beginning at the given starting position.
The spiral follows this direction order: right → down → left → up. Whenever the next position would go outside the matrix boundary or reach a previously filled cell, turn clockwise and continue.
这道题要求从给定起点开始,按“右、下、左、上”的顺时针顺序,把数字 1, 2, 3… 依次填入矩阵。核心思路通常是模拟行走过程:用方向数组控制移动方向,用已访问标记或边界判断来决定何时转向。由于要处理越界和重复访问,最稳妥的方法是逐步生成每个坐标并检查合法性,直到填满矩阵。题目重点在于矩阵模拟、方向切换和边界控制,适合用作在线评测中的实现题。