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

歡迎光臨散文網(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ó)家法律
金昌市| 西盟| 九江县| 东兰县| 平南县| 历史| 岳阳市| 乌海市| 博乐市| 张家界市| 乡宁县| 宜城市| 区。| 桑日县| 黄龙县| 兴文县| 阿勒泰市| 大宁县| 武宁县| 宝坻区| 井陉县| 唐山市| 天门市| 新乡县| 德州市| 聊城市| 惠安县| 深泽县| 汝州市| 青龙| 西乡县| 双城市| 同仁县| 马山县| 民权县| 桃江县| 射阳县| 开化县| 崇州市| 胶南市| 白玉县|