Skip to content

Commit

Permalink
Merge pull request #427 from hyejjun/main
Browse files Browse the repository at this point in the history
[ํ˜œ์ค€] Week4 ๋ฌธ์ œํ’€์ด
  • Loading branch information
hyejjun authored Sep 6, 2024
2 parents 0f69d7f + 5267a7e commit 1b9c9e6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions missing-number/hyejjun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @param {number[]} nums
* @return {number}
*/
var missingNumber = function (nums) {
let n = nums.length;
let expectedSum = n * (n + 1) / 2;

let actualSum = nums.reduce((acc, curr) => acc + curr, 0);

return expectedSum - actualSum;
};

console.log(missingNumber([3, 0, 1]));
console.log(missingNumber([0, 1]));
console.log(missingNumber([9, 6, 4, 2, 3, 5, 7, 0, 1]));

/*
์‹œ๊ฐ„ ๋ณต์žก๋„: O(n)
๊ณต๊ฐ„ ๋ณต์žก๋„: O(1)
*/
20 changes: 20 additions & 0 deletions valid-palindrome/hyejjun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function (s) {
let cleanedString = s.toLowerCase().replace(/[^a-z0-9]/g, '');

let reversedString = cleanedString.split('').reverse().join('');

return cleanedString === reversedString;
};

console.log(isPalindrome("A man, a plan, a canal: Panama"));
console.log(isPalindrome("race a car"));
console.log(isPalindrome(" "));

/*
์‹œ๊ฐ„ ๋ณต์žก๋„: O(n)
๊ณต๊ฐ„ ๋ณต์žก๋„: O(n)
*/

0 comments on commit 1b9c9e6

Please sign in to comment.