Merge pull request #1180 from xiaofei-2020/back07

添加(0039.组合总和.md):增加typescript版本
This commit is contained in:
程序员Carl
2022-04-13 09:48:21 +08:00
committed by GitHub

View File

@ -392,7 +392,34 @@ var combinationSum = function(candidates, target) {
};
```
## TypeScript
```typescript
function combinationSum(candidates: number[], target: number): number[][] {
const resArr: number[][] = [];
function backTracking(
candidates: number[], target: number,
startIndex: number, route: number[], curSum: number
): void {
if (curSum > target) return;
if (curSum === target) {
resArr.push(route.slice());
return
}
for (let i = startIndex, length = candidates.length; i < length; i++) {
let tempVal: number = candidates[i];
route.push(tempVal);
backTracking(candidates, target, i, route, curSum + tempVal);
route.pop();
}
}
backTracking(candidates, target, 0, [], 0);
return resArr;
};
```
## C
```c
int* path;
int pathTop;