国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 130. Surrounded Regions

2022-11-18 20:50 作者:您是打尖兒還是住店呢  | 我要投稿

Given an?m x n?matrix?board?containing?'X'?and?'O',?capture all regions that are 4-directionally?surrounded by?'X'.

A region is?captured?by flipping all?'O's into?'X's in that surrounded region.

?

Example 1:

Input: board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]Output: [["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]]Explanation: Notice that an 'O' should not be flipped if: - It is on the border, or - It is adjacent to an 'O' that should not be flipped. The bottom 'O' is on the border, so it is not flipped. The other three 'O' form a surrounded region, so they are flipped.

Example 2:

Input: board = [["X"]]Output: [["X"]]

?

Constraints:

  • m == board.length

  • n == board[i].length

  • 1 <= m, n <= 200

  • board[i][j]?is?'X'?or?'O'.


典型的DFS先將邊上的為O的改成#,然后dfs跟他相關(guān)聯(lián)的位置也一并改成#,剩下的O就是唄X包圍著的,然后2個(gè)for循環(huán)就可以了。



Runtime:?4 ms, faster than?63.84%?of?Java?online submissions for?Surrounded Regions.

Memory Usage:?52.7 MB, less than?13.82%?of?Java?online submissions for?Surrounded Regions.

Next challenges:

Walls and Gates


LeetCode 130. Surrounded Regions的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
尼勒克县| 罗定市| 博客| 永嘉县| 明光市| 内乡县| 辉南县| 永清县| 邢台县| 封丘县| 平顶山市| 循化| 嘉禾县| 怀集县| 香河县| 安平县| 遂昌县| 山东省| 濉溪县| 肇州县| 东宁县| 灌南县| 利辛县| 丹阳市| 九江市| 东平县| 金溪县| 秦皇岛市| 株洲市| 商南县| 将乐县| 恭城| 江阴市| 承德县| 盐池县| 百色市| 五常市| 太白县| 休宁县| 商水县| 七台河市|