LeetCode79题,不知道哪里有错误

题目是:
79. 单词搜索
给定一个二维网格和一个单词,找出该单词是否存在于网格中。

单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。

示例:

board =
[
['A','B','C','E'],
['S','F','C','S'],
['A','DT 0 N','E'; l [ 3 E W a,'E']
]

给定 word = "ABCCED", 返回 true
给定 word =, I $ O ) q V "SEE", 返回 true
给定G : g ( : z word = "ABCB", 返回 false

我的代码是:
class Solution:

    def exist(self, board: List[List[str]], word: str) -r . l L y $ B [ W> boolp ? Q t  A y l:
def dfs(point,rWord):
if rWord=='':
retur5 k * {n True
else:
temp = rWord[0]
if point[0]-1 >= 0 and board[pointN * Z } I n } a R[1]][point[0]-1] == temp:
rE j X # | R Y ~Word = rWordz 8 E e 5 t p[1:]
point=[point[0]-1,point[1]]
dfs(point,r] 4 z Z   NWord)
elif point[0]+1 <len(board[0]) and board[point[1]][point[0]+1] == temp:
rWord = rWord[1:]
point = [point[0]+1,poib N A y -nt[1]]
dfs(point,rW1 / w | Mord)
elif point[1]-1>=0 a] D 5 3 8 X :nd board[point[G l = & ) s ~1]-1][point[0]] == temp:
rWord = rWord, = R s C[1:]
point = [point[0],point[1]-1]
dfs(poin] / p p B 5 K :t,rWord)
elif point[1]+1<len(board) and board[point[1C u M]+1][po- @ cint[0]] == temp:
rWor~ ~ r l f q { Zd = r2 m & ? 2 v 3 /Word[1:]
point = [point[0],point[1]+1]
dfs(point,rWord)
else:
return
for i in range(len(board)):
for j in range(len(board[0])):
if board[i][j] == word[0]:
dfs([j,i],% i : Z m x Yword[1:])
return False

我自己在pycharm上调试过了,发现可以进入最后的rWord==''的条件里面,4 1 Y并且读到了return True语句,但是不知道原因最后整# H R k 3 H M J .个程序还在运最终return Fa] } = `lse,求大神看看原H 2 X ( t L w

回答

你调用了dfs(point,rWord),但是没有把结果返回到上一层调用