Skip to content
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

[구문영] Week1 문제 풀이 #311

Merged
merged 8 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions contains-duplicate/GUMUNYEONG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function (nums) {
const setObj = new Set(nums);

const diff = !(nums.length === setObj.size);

return diff;
};

// TC: O(n)
// SC: O(n)
Copy link
Contributor

Choose a reason for hiding this comment

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

마지막에 line break 없는 파일이 메인 브랜치에 유입되지 않도록 각별히 주의바랍니다. (참고: #334)

17 changes: 17 additions & 0 deletions number-of-1-bits/GUMUNYEONG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {number} n
* @return {number}
*/
var hammingWeight = function (n) {
let i = "1";

while (n > 2) {
n % 2 ? i += "1" : "";
n = Math.floor(n / 2);
}

return i.length;
};

// TC: O(log n)
// SC: O(log n)
Copy link
Contributor

@DaleSeo DaleSeo Aug 17, 2024

Choose a reason for hiding this comment

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

공간 복잡도 분석이 정확한지 재고해보시면 좋을 것 같아요!

22 changes: 22 additions & 0 deletions top-k-frequent-elements/GUMUNYEONG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @param {number[]} nums
* @param {number} k
* @return {number[]}
*/
var topKFrequent = function (nums, k) {
let result = [];
let fObj = {};

for (let i = 0; i < nums.length; i++) {
const n = nums[i];
fObj[n] ? fObj[n]++ : fObj[n] = 1;
}

Object
.entries(fObj)
.sort((a, b) => b[1] - a[1])
.slice(0, k)
.filter(v => result.push(v[0]));

return result;
};