标签:subject style 入行 return turn pytho 多少 count 回溯
# -*- coding:utf-8 -*- class Solution: def __init__(self): self.count = 0 def movingCount(self, threshold, rows, cols): # write code here arr = [[1 for i in range(rows)]for j in range(cols)] self.count_path(arr,0,0,threshold) return self.count def count_path(self,arr,i,j,k): if i<0 or j<0 or i>=len(arr) or j>=len(arr[0]): return tmpi = list(map(int, list(str(i)))) tmpj = list(map(int, list(str(j)))) if sum(tmpi)+sum(tmpj)>k or arr[i][j]!=1: return arr[i][j] = 0 self.count+=1 self.count_path(arr,i+1,j,k) self.count_path(arr,i-1,j,k) self.count_path(arr,i,j+1,k) self.count_path(arr,i,j-1,k)
标签:subject style 入行 return turn pytho 多少 count 回溯
原文地址:https://www.cnblogs.com/ansang/p/11873447.html