We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0c39e43 commit e6b5d26Copy full SHA for e6b5d26
backtracking/combination_sum.py
@@ -47,8 +47,18 @@ def combination_sum(candidates: list, target: int) -> list:
47
>>> combination_sum([-8, 2.3, 0], 1)
48
Traceback (most recent call last):
49
...
50
- RecursionError: maximum recursion depth exceeded
+ ValueError: All elements in candidates must be non-negative
51
+ >>> combination_sum([], 1)
52
+ Traceback (most recent call last):
53
+ ...
54
+ ValueError: Candidates list should not be empty
55
"""
56
+ if not candidates:
57
+ raise ValueError("Candidates list should not be empty")
58
+
59
+ if any(x < 0 for x in candidates):
60
+ raise ValueError("All elements in candidates must be non-negative")
61
62
path = [] # type: list[int]
63
answer = [] # type: list[int]
64
backtrack(candidates, path, answer, target, 0)
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments