Skip to content

Commit 1d1797c

Browse files
authored
Merge pull request #677 from suhacs/main
[phenomenal_star_75309]
2 parents 0f9a77f + 958eaf1 commit 1d1797c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

contains-duplicate/suhacs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function containsDuplicate(nums) {
2+
const setLength = [...new Set(nums)].length;
3+
const numLength = nums.length;
4+
return numLength === setLength ? false : true;
5+
}
6+
console.log(containsDuplicate([1, 1, 1, 3, 3, 4, 3, 2, 4, 2]));
7+
//

top-k-frequent-elements/suhacs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.
2+
3+
function top_k_frequent_element(numArr, k) {
4+
let element_qty = [];
5+
const numSet = [...new Set(numArr)];
6+
for (num of numSet) {
7+
const count = numArr.filter((x) => x === num).length;
8+
element_qty.push({ [num]: count });
9+
}
10+
Object.keys(element_qty).forEach((key) => element_qty[key]);
11+
}
12+
13+
const Arr = [1, 2, 3, 4, 5, 5, 5, 5, 3, 3, 32, 2, 2, 1];
14+
top_k_frequent_element(Arr);

valid-palindrome/suhacs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function isValidPalindrome(text) {
2+
let refinedTxt = text
3+
.replaceAll(/[^a-zA-Z0-9]/g, "")
4+
.replaceAll(" ", "")
5+
.toLowerCase();
6+
console.log(refinedTxt === [...refinedTxt].reverse().join("") ? true : false);
7+
return refinedTxt === [...refinedTxt].reverse().join("") ? true : false;
8+
}
9+
10+
isValidPalindrome("A man, a plan, a canal: Panama"); //true
11+
isValidPalindrome("race a car"); //false
12+
isValidPalindrome(" "); //true

0 commit comments

Comments
 (0)