Skip to content

Commit 738de32

Browse files
authored
Merge pull request DaleStudy#2462 from DaleStudy/yihyun-kim1
[yihyun-kim1] WEEK 03 Solutions
2 parents 805c5dc + ce0ae12 commit 738de32

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

maximum-subarray/yihyun-kim1.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const maxSubArray = (nums) => {
6+
let currentSum = nums[0];
7+
let maxSum = nums[0];
8+
9+
for (let i = 1; i < nums.length; i++) {
10+
currentSum = Math.max(nums[i], currentSum + nums[i]);
11+
maxSum = Math.max(maxSum, currentSum);
12+
}
13+
14+
return maxSum;
15+
};

number-of-1-bits/yihyun-kim1.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const hammingWeight = (n) => {
6+
const binary = n.toString(2);
7+
return binary.split("").filter((bit) => bit === "1").length;
8+
};

valid-palindrome/yihyun-kim1.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
const isPalindrome = (s) => {
6+
const cleaned = s.toLowerCase().replace(/[^a-z0-9]/g, "");
7+
const flipped = cleaned.split("").reverse().join("");
8+
9+
return cleaned === flipped;
10+
};

0 commit comments

Comments
 (0)