Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update 0039-combination-sum.js
  • Loading branch information
pobch authored Jun 15, 2023
commit 7b7774ba105b28c67f2d8d5311d6695be73d09f5
5 changes: 3 additions & 2 deletions javascript/0039-combination-sum.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* https://leetcode.com/problems/combination-sum/
* Time O(N^(Target/MIN)) | Space O(Target/Min)
* Time: O((Target/MIN)*(2^k)) where k is the sum of target/candidate[i] from i = 0 to size of candidate - 1
* Space: O(Target/MIN)
* @param {number[]} candidates
* @param {number} target
* @return {number[][]}
Expand All @@ -10,7 +11,7 @@
if (isBaseCase) return combinations;

const isTarget = target === 0;
if (isTarget) return combinations.push(combination.slice());
if (isTarget) return combinations.push(combination.slice()); // Time of calling slice(): Target/MIN

for (let i = index; i < candidates.length; i++) {
backTrack(candidates, target, i, combination, combinations);
Expand Down