From 8ef273330de4c5bf011e40ca6157e6e4f90a1781 Mon Sep 17 00:00:00 2001 From: haiker2011 Date: Sun, 30 Sep 2018 21:35:18 +0800 Subject: [PATCH] add #13 #14 python implement --- notes/面试总结.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/notes/面试总结.md b/notes/面试总结.md index 06298c75..96728367 100644 --- a/notes/面试总结.md +++ b/notes/面试总结.md @@ -1016,6 +1016,40 @@ private void initDigitSum() { } ``` +```python +# -*- coding:utf-8 -*- +class Solution: + def __init__(self): + self.acc = 0 + + def movingCount(self, threshold, rows, cols): + # write code here + self.threshold = threshold + self.rows = rows + self.cols = cols + self.board = [[0 for _ in range(cols)] for _ in range(rows)] + + self.traverse(0,0) + return self.acc + + def block(self, r, c): + s = sum(map(int,str(r)+str(c))) + return s>self.threshold + + def traverse(self, r, c): + if not (0<=r