[LeetCode] 54. Spiral Matrix
여전히 쓸데없는 실수가 잦다. 재귀를 이용했고, 방문 지점을 음수로 덮어서 처리하려그랬는데, matrix에 값이 -100~100 까지인지를 안보고 했다가 Submit 한번을 날렸다. 그 외에도 놓친 부분이 많았다. 재귀를 써도 되고, 메모리를 줄이고 싶다면 for loop도 충분히 가능한 문제로 보인다. class Solution { vector result; int direction[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} }; int cur_direction = 0; public: void dfs ( int y, int x, vector& matrix ) { result.push_back(matrix[y][x]); matrix[y][x] = -999; int nex..
2021. 3. 30.