Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions contains-duplicate/Jeehay28.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function (nums) {
return nums.length !== new Set(nums).size;
};
25 changes: 25 additions & 0 deletions top-k-frequent-elements/Jeehay28.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @param {number[]} nums
* @param {number} k
* @return {number[]}
*/
var topKFrequent = function (nums, k) {
let result = [];

const obj = nums.reduce((acc, cur) => {
acc[cur] = (acc[cur] || 0) + 1;
return acc;
}, {});

const frequentValues = Object.values(obj)
.sort((a, b) => b - a)
.slice(0, k);

for (const [key, value] of Object.entries(obj)) {
if (frequentValues.includes(value)) {
result.push(parseInt(key));
}
}

return result;
};
17 changes: 17 additions & 0 deletions valid-palindrome/Jeehay28.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function (s) {
const reg = /[a-z0-9]/g;
const converted = s.toLowerCase().match(reg);
Comment on lines +6 to +7
Copy link
Contributor

Choose a reason for hiding this comment

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

upper case도 정규식에 포함하면 논리의 흐름이 더 좋을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

리뷰 감사합니당~


if (converted === null) {
return true;
} else {
const forward = converted.join("");
const backward = converted.reverse().join("");

return forward === backward;
}
};
Loading