← 返回 uber 的题目列表Shortest Bridge
类型:qbank
Given a binary grid with exactly two islands (1 = land, 0 = water), return the minimum number of 0s that must be flipped to connect the two islands.
Shortest Bridge
Given a binary grid with exactly two islands (1 = land, 0 = water), return the minimum number of 0s that must be flipped to connect the two islands.
SWE
bfs
dfs
grid
medium
Frequency
Single report
Last asked
2026-02-21
Stage
phone-screen
Shortest Bridge
You are given a binary grid containing exactly two islands, where 1 is land and 0 is water.
Return the minimum number of 0s that must be flipped to connect the two islands.
Examples
Example 1:
Input: grid = [[0,1],[1,0]]
Output: 1
Example 2:
Input: grid = [[0,1,0],[0,0,0],[0,0,1]]
Output: 2
Constraints
2 <= grid.length == grid[i].length <= 100
There are exactly two islands in grid.