解題說明
C++ 解法
複雜度分析
虛擬碼
1. Initialize queue with all gate (0) positions
2. Define dirs = [up, down, left, right]
3. While queue not empty:
a. Dequeue cell (r, c)
b. For each neighbor (nr, nc) in 4 directions:
- If in bounds AND rooms[nr][nc] == INF:
* rooms[nr][nc] = rooms[r][c] + 1
* Enqueue (nr, nc)
4. (Rooms unreachable from any gate remain INF)