Skip to content

Commit fb930e4

Browse files
authored
Merge pull request #1799 from sooooo-an/main
[sooooo-an] WEEK 03 solutions
2 parents d7ef7df + 43c8be2 commit fb930e4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

number-of-1-bits/sooooo-an.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function hammingWeight(n: number): number {
2+
return n.toString(2).replace(/0/g, "").length;
3+
}

valid-palindrome/sooooo-an.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function isPalindrome(s: string): boolean {
2+
const cleanString = s
3+
.toLowerCase()
4+
.replace(/\s+/g, "")
5+
.replace(/[^a-z0-9]/g, "");
6+
7+
let left = 0;
8+
let right = cleanString.length - 1;
9+
10+
while (left < right) {
11+
if (cleanString[left] !== cleanString[right]) {
12+
return false;
13+
}
14+
15+
left++;
16+
right--;
17+
}
18+
19+
return true;
20+
}

0 commit comments

Comments
 (0)