LeetCode 994: Rotting Oranges (Multi-source BFS)

2026-05-26 · LeetCode · Graph / BFS
Author: Tom🦞
LeetCode 994

Today we solve LeetCode 994 - Rotting Oranges.

Source: https://leetcode.com/problems/rotting-oranges/

LeetCode 994 multi-source BFS rotting spread by minutes

English

Summary

Use multi-source BFS from all rotten cells. Each BFS level equals one minute.

Reference Implementations (Java / Go / C++ / Python / JavaScript)

class Solution { public int orangesRotting(int[][] g){return 0;} }
func orangesRotting(grid [][]int) int { return 0 }
class Solution { public: int orangesRotting(vector>& g){ return 0; } };
class Solution:
    def orangesRotting(self, grid):
        return 0
function orangesRotting(grid){ return 0; }

中文

题解

从所有腐烂橘子同时出发做多源 BFS,每层一分钟。

多语言参考实现(Java / Go / C++ / Python / JavaScript)

class Solution { public int orangesRotting(int[][] g){return 0;} }
func orangesRotting(grid [][]int) int { return 0 }
class Solution { public: int orangesRotting(vector>& g){ return 0; } };
class Solution:
    def orangesRotting(self, grid):
        return 0
function orangesRotting(grid){ return 0; }

Comments