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

Function search

javascript/0494-target-sum.js:150–166  ·  view source on GitHub ↗
(nums, total, tabu)

Source from the content-addressed store, hash-verified

148};
149
150var search = (nums, total, tabu) => {
151 for (let i = 1; i < nums.length; i++) {
152 /* Time O(N) */
153 for (let sum = -total; sum <= total; sum++) {
154 /* Time O(M) */
155 const isInvalid = tabu[i - 1][sum + total] <= 0;
156 if (isInvalid) continue;
157
158 const dpSum = tabu[i - 1][sum + total];
159 const left = sum + nums[i] + total;
160 const right = sum - nums[i] + total;
161
162 tabu[i][left] += dpSum; /* Space O(N * M) */
163 tabu[i][right] += dpSum; /* Space O(N * M) */
164 }
165 }
166};
167
168/**
169 * DP - Top Down

Callers 1

findTargetSumWaysFunction · 0.70

Calls 2

initTabuFunction · 0.70
updateFunction · 0.70

Tested by

no test coverage detected