Skip to content

Commit 4fb3617

Browse files
39. Combination Sum
1 parent a01af81 commit 4fb3617

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44
## 78. Subsets
55

66
1. Intuition: Need to find all possible subset (super-set/the power set), backtracking
7-
2. Choice : all the numbers in the unique array
8-
3. Choose : one element at a time (this can be done by in recursive call by current choice index + 1 )
9-
4. Explore : recursive cal on above choose and next choice
10-
5. Un-choose : remove the chosen element
11-
6. Explore : recursive cal on above un-choose and the next choice
7+
2. if start index >= len(nums) : add path into result and return
8+
3. Choice : all the numbers in the unique array
9+
4. Choose : add one element at a time on path (this can be done by in recursive call by current choice index + 1 )
10+
5. Explore : recursive cal on above choose and next choice
11+
6. Un-choose : remove the chosen element from path
12+
7. Explore : recursive cal for next choice
1213

1314
--------
1415
### 39. Combination Sum
15-
16-
16+
Need to find all possible combination of given target where numbers can be repetitive
17+
1. Intuition: Need to find all combination - hence backtracking.
18+
1. Same as 78. Subset with once change, instead of choosing new number each time, chose same number until,
19+
2. if start index >= len(nums) and target == sum of path: add path into result and return
20+
3. if index >= len(nums) OR target > sum of path: return, it means that path does't contains the sum
21+
4. Choice: all the numbers
22+
5. Choose: One element until either target == sum of path
23+
6. Explore: recursive call for same start point
24+
7. Un-choose: remove the added element from path
25+
8. Explore: recursive call on next number
1726

1827

1928

0 commit comments

Comments
 (0)