MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / canPartition

Function canPartition

javascript/0416-partition-equal-subset-sum.js:8–18  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

6 * @return {boolean}
7 */
8var canPartition = (nums) => {
9 const sum = getSum(nums); /* Time O(N) */
10 const subSetSum = sum / 2;
11
12 const isEven = sum % 2 === 0;
13 if (!isEven) return false;
14
15 const index = nums.length - 1;
16
17 return dfs(nums, index, subSetSum);
18};
19
20var getSum = (nums, sum = 0) => {
21 for (const num of nums) sum += num; /* Time O(N) */

Callers

nothing calls this directly

Calls 5

getSumFunction · 0.70
dfsFunction · 0.70
initMemoFunction · 0.70
initTabuFunction · 0.70
searchFunction · 0.70

Tested by

no test coverage detected