最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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ó)家法律
莱芜市| 思南县| 滨海县| 木里| 黄大仙区| 田东县| 商都县| 凯里市| 凤冈县| 盐源县| 蕲春县| 全南县| 屯留县| 张家港市| 侯马市| 吴旗县| 房产| 建宁县| 雅江县| 台北县| 广元市| 慈溪市| 分宜县| 洛南县| 依兰县| 四子王旗| 嵊泗县| 玉林市| 黑河市| 阿拉善右旗| 南安市| 松江区| 堆龙德庆县| 庆安县| 福鼎市| 龙游县| 宽城| 宁远县| 扬州市| 双城市| 原阳县|