Skip to content

Commit f1eee0e

Browse files
committed
Docs: add description for solved questions
1 parent b300fb0 commit f1eee0e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

contains-duplicate/HC-kang.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Input: nums = [1,1,1,3,3,4,3,2,4,2]
1414
Output: true
1515
*/
1616

17+
// Time complexity: O(n)
18+
// Space complexity: O(n)
1719
function containsDuplicate(nums: number[]): boolean {
1820
return nums.length !== new Set(nums).size;
1921
}

number-of-1-bits/HC-kang.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ The input binary string 1111111111111111111111111111101 has a total of thirty se
2121
*/
2222

2323
function hammingWeight(n: number): number {
24+
// Time complexity: O(logn)
25+
// Space complexity: O(logn)
26+
// but it has a better readability
2427
return n.toString(2).split('1').length - 1;
2528

26-
// let count = 0;
27-
// while (n !== 0) {
28-
// count += n & 1;
29-
// n >>>= 1;
30-
// }
31-
// return count;
29+
// Time complexity: O(logn)
30+
// Space complexity: O(1)
31+
let count = 0;
32+
while (n !== 0) {
33+
count += n & 1;
34+
n >>>= 1;
35+
}
36+
return count;
3237
}

0 commit comments

Comments
 (0)