Skip to content

Commit

Permalink
添加(0039.组合总和.md):增加typescript版本
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofei-2020 committed Mar 28, 2022
1 parent 1d19c5b commit 4959bd4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions problems/0039.组合总和.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4959bd4

Please sign in to comment.