
나선형 메트릭스는 대부분의 알고리즘 풀이 사이트에서도 많이 등장하는 문제이다.
해결 방법은 직접 요소를 순회하며 방문 가능한 요소의 축을 축소하는 방식으로 풀이됨
function spiralOrder(matrix: number[][]): number[] {
    const result = []
    const rowLen = matrix.length
    const colLen = matrix[0].length
    let [top, right, bottom, left] = [0, colLen - 1, rowLen - 1, 0]
    while(top <= bottom && left <= right) {
        // 우측으로 이동
        for(let i = left; i <= right; i++) result.push(matrix[top][i])
        top++
        // 하단으로 이동
        for(let i = top; i <= bottom; i++) result.push(matrix[i][right])
        right--
        if (top <= bottom) {
            // 좌측으로 이동
            for (let i = right; i >= left; i--) result.push(matrix[bottom][i]);
            bottom--;
        }
        if (left <= right) {
            // 상단으로 이동
            for (let i = bottom; i >= top; i--) result.push(matrix[i][left]);
            left++;
        }
    }
    return result
};