Backtracking
1 | class Solution { |
Remarks:
- Remember that the numbers can be used for multiple times so in backtracking we set the next index
i
instead ofi+1
. - Template for backtracking:
1
2
3
4
5
6
7
8
9
10void backTracking(params) {
...
if (endCondition) {
saveResult();
return;
}
...
backTracking(nextParams);
...
}