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
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),
backtracking approach using recursion is needed to handle it.
number of result, we dont need to consider dynamic programming.
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`:
```
0
/ \
+2 +3
/ \ \
+2 +3 +3
/ \ / \ \
+2 ✘ ✘ ✘ ✓
/ \
✓ ✘
0
/ \
+3 +2
/ \ \
+3 +2 +2
/ \ \
✓ +2 +2
\ \
✘ ✓
```
## References