상위 150개 인터뷰쉬움

주변 지역

'주변 지역' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

'X'와 'O'를 포함하는 m x n 매트릭스 보드가 주어지면 'X'로 둘러싸인 4방향의 모든 영역을 캡처합니다.

영역은 둘러싸인 영역의 모든 'O'를 'X'로 뒤집어서 캡처됩니다.

수정된 보드를 반환하는 solve(board: List[List[str]]) -> List[List[str]] 함수를 작성하세요.

제약
  • m == len(board)
  • n == len(board[i])
  • 1 <= m, n <= 200
  • board[i][j] is 'X' or 'O'

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

Surrounded regions should not be on the border, which means any 'O' on the border of the board is not flipped to 'X'. Any 'O' that is connected to a border 'O' is also not flipped.

Need a Hint?
세트나 힙과 같은 그래프 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.