AcWing 24. 机器人的运动范围 python
原题链接
简单
作者:
acwing_827
,
2019-09-03 10:46:08
,
所有人可见
,
阅读 997
class Solution(object):
def movingCount(self, threshold, rows, cols):
"""
:type threshold: int
:type rows: int
:type cols: int
:rtype: int
"""
self.t = threshold
self.rows = rows
self.cols = cols
self.flag = [([0]*cols) for i in range(rows)]
self.count = 0
self.walk(0,0)
return self.count
def walk(self, i,j):
if i<0 or i>=self.rows or j<0 or j>=self.cols or self.flag[i][j]==1:
return None
if sum(list(map(int, list(str(i))+list(str(j)) ))) > self.t:
return None
self.count+=1
self.flag[i][j] = 1
self.walk(i+1, j)
self.walk(i, j+1)