diff --git a/contains-duplicate/0-chan.ts b/contains-duplicate/0-chan.ts new file mode 100644 index 000000000..e768f9c9e --- /dev/null +++ b/contains-duplicate/0-chan.ts @@ -0,0 +1,8 @@ +/** + * time complexity : O(n) + * space complexity : O(n) + */ +function containsDuplicate(nums: number[]): boolean { + const hasDuplicate = new Set(nums).size !== nums.length; + return hasDuplicate; +}; diff --git a/number-of-1-bits/0-chan.ts b/number-of-1-bits/0-chan.ts new file mode 100644 index 000000000..17b8fdba2 --- /dev/null +++ b/number-of-1-bits/0-chan.ts @@ -0,0 +1,10 @@ +/** + * time complexity : O(logn) + * space complexity : O(logn) + */ +function hammingWeight(n: number): number { + const MAX_NUM = 2147483648 - 1; + + const bitwiseOperated = (n & MAX_NUM).toString(2); + return bitwiseOperated.replaceAll('0', '').length; +};