상위 150개 인터뷰쉬움

단어 검색

'단어 검색' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

문자 보드의 m x n 그리드와 문자열 단어가 주어지면 그리드에 단어가 있으면 true를 반환합니다.

단어는 순차적으로 인접한 셀의 문자로 구성될 수 있으며, 인접한 셀은 수평 또는 수직으로 이웃합니다. 동일한 문자 셀은 두 번 이상 사용할 수 없습니다.

exist(board: list, word: str) -> bool 함수를 구현하세요.

제약
  • m == board.length
  • n == board[i].length
  • 1 <= m, n <= 6
  • 1 <= word.length <= 15
  • board and word consists of only lowercase and uppercase English letters

Example 1
Input
[["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], "ABCCED"
Output
True
Explanation

The word ABCCED can be traced: A(0,0)->B(0,1)->C(0,2)->C(1,2)->E(2,2)->D(2,1).

Example 2
Input
[["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], "SEE"
Output
True
Explanation

The word SEE can be traced: S(1,3)->E(2,3)->E(2,2).

Example 3
Input
[["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], "ABCB"
Output
False
Explanation

Cannot trace ABCB without reusing cells.

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 리소스

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