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

Function count

javascript/0287-find-the-duplicate-number.js:90–103  ·  view source on GitHub ↗
(nums, bit)

Source from the content-addressed store, hash-verified

88};
89
90const count = (nums, bit) => {
91 let [baseCount, numsCount, mask] = [0, 0, 1 << bit];
92
93 for (let i = 0; i < nums.length; i++) {
94 /* Time O(N) */
95 const isBaseBitSet = 0 < (i & mask);
96 if (isBaseBitSet) baseCount++;
97
98 const isNumBitSet = 0 < (nums[i] & mask);
99 if (isNumBitSet) numsCount++;
100 }
101
102 return [baseCount, numsCount, mask];
103};
104
105/**
106 * https://leetcode.com/problems/find-the-duplicate-number/

Callers 1

findDuplicateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected