Update combinationSum README to reflect new implementation

This commit is contained in:
casca 2020-01-30 21:33:47 +01:00 committed by GitHub
parent f6408ffb57
commit 2f60cab835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,21 +38,22 @@ A solution set is:
## Explanations ## Explanations
Since the problem is to get all the possible results, not the best or the Since the problem is to get all the possible results, not the best or the
number of result, thus we dont need to consider DP (dynamic programming), number of result, we dont need to consider dynamic programming.
backtracking approach using recursion is needed to handle it. We do instead a depth-first traversal of the decision tree,
using an iterative implementation to avoid stack overflows.
Here is an example of decision tree for the situation when `candidates = [2, 3]` and `target = 6`: Here is an example of decision tree for the situation when `candidates = [2, 3]` and `target = 6`:
``` ```
0 0
/ \ / \
+2 +3 +3 +2
/ \ \ / \ \
+2 +3 +3 +3 +2 +2
/ \ / \ \ / \ \
+2 ✘ ✘ ✘ ✓ ✓ +2 +2
/ \ \ \
✓ ✘ ✘ ✓
``` ```
## References ## References