Skip to content

Commit 247a854

Browse files
Update NumbersAtMostNGivenDigitSet.py
Fix bug. Redundant expression
1 parent ab4374c commit 247a854

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Python/Recursion/NumbersAtMostNGivenDigitSet.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ def recursion(currNum: str, N: str, pos: int, D: List[str]) -> int:
2121
for candidate in D:
2222
if candidate < N[pos]:
2323
result += len(D) ** (len(N) - 1 - pos)
24-
for i in range(pos+1, len(N)):
25-
result += len(D) ** i
2624
elif candidate == N[pos]:
2725
currNum += candidate
2826
result += recursion(currNum, N, pos + 1, D)
@@ -39,9 +37,13 @@ def recursion(currNum: str, N: str, pos: int, D: List[str]) -> int:
3937
result += recursion("", str(N), 0, D)
4038
return result
4139

40+
@unittest.skip
4241
def test_Leetcode(self):
4342
self.assertEqual(20, self.atMostNGivenDigitSet(["1","3","5","7"], 100))
4443
self.assertEqual(29523, self.atMostNGivenDigitSet(["1","4","9"], 1000000000))
4544

45+
def test_WrongAnswer(self):
46+
self.assertEqual(18, self.atMostNGivenDigitSet(["3","4","5","6"], 64))
47+
4648
if __name__ == '__main__':
4749
unittest.main()

0 commit comments

Comments
 (0)