diff --git a/content/leetcode/2023/8.md b/content/leetcode/2023/8.md index 962b123a0..99ac1c814 100644 --- a/content/leetcode/2023/8.md +++ b/content/leetcode/2023/8.md @@ -3,6 +3,40 @@ title: "2023.8" draft: false --- +# 2023.8.26 + +```python +# +# @lc app=leetcode.cn id=39 lang=python3 +# +# [39] 组合总和 +# + +# @lc code=start +from typing import List + + +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + res = [] + + def dfs(candidates, target, path): + if target == 0: + res.append(path) + return + elif target < 0: + return + else: + for i in range(len(candidates)): + dfs(candidates[i:], target - candidates[i], path + [candidates[i]]) + + dfs(candidates, target, []) + return res + + +# @lc code=end +``` + # 2023.8.25 ```python