Skip to content

[강희찬] Week1 문제 풀이 #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions contains-duplicate/HC-kang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
217. Contains Duplicate

Example 1:
Input: nums = [1,2,3,1]
Output: true

Example 2:
Input: nums = [1,2,3,4]
Output: false

Example 3:
Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true
*/

function containsDuplicate(nums: number[]): boolean {
return nums.length !== new Set(nums).size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set의 속성을 잘 활용하시네요. 이런방법이 있는지 몰랐네요👍

}
32 changes: 32 additions & 0 deletions number-of-1-bits/HC-kang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
191. Number of 1 Bits

Example 1:
Input: n = 11
Output: 3
Explanation:
The input binary string 1011 has a total of three set bits.

Example 2:
Input: n = 128
Output: 1
Explanation:
The input binary string 10000000 has a total of one set bit.

Example 3:
Input: n = 2147483645
Output: 30
Explanation:
The input binary string 1111111111111111111111111111101 has a total of thirty set bits.
*/

function hammingWeight(n: number): number {
return n.toString(2).split('1').length - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string 메서드 관련 시간복잡도는 모르고있었는데 리뷰하면서 알게됐네요 :)


// let count = 0;
// while (n !== 0) {
// count += n & 1;
// n >>>= 1;
// }
// return count;
}