讨论/《画解剑指 Offer》 - 剑指 Offer 13. 机器人的运动范围/
《画解剑指 Offer》 - 剑指 Offer 13. 机器人的运动范围
共 1 个回复
class Solution:
    def movingCount(self, m: int, n: int, k: int) -> int:
        def dfs(m,n,i,j,k,visited):
            if 0<=i<m and 0<=j<n and visited[i][j]==False and (i%10+i//10 + j%10 +j//10)<=k:
                visited[i][j] = True
                return dfs(m,n,i+1,j,k,visited)+dfs(m,n,i,j+1,k,visited)+1
            else:
                return 0 
                
        visited = [[False]*n for _ in range(m)]
        return dfs(m,n,0,0,k,visited)