Skip to content

Commit 53437d6

Browse files
authored
Merge pull request #1316 from sukyoungshin/main
2 parents 996bd6a + a7acca0 commit 53437d6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

number-of-1-bits/sukyoungshin.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function hammingWeight(n: number): number {
2+
let count = 0;
3+
let num = n;
4+
5+
while (num > 0) {
6+
if (num % 2 === 1) {
7+
count++;
8+
}
9+
num = Math.floor(num / 2);
10+
}
11+
12+
return count;
13+
};

valid-palindrome/sukyoungshin.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const alphaNumSet = new Set([..."abcdefghijklmnopqrstuvwxyz0123456789"]);
2+
3+
function isPalindrome(s: string): boolean {
4+
let normalized = "";
5+
6+
for (const characters of s) {
7+
const lower = characters.toLowerCase();
8+
if (alphaNumSet.has(lower)) {
9+
normalized += lower;
10+
}
11+
}
12+
13+
let left = 0;
14+
let right = normalized.length - 1;
15+
while (left < right) {
16+
if (normalized[left] !== normalized[right]) {
17+
return false;
18+
}
19+
left++;
20+
right--;
21+
}
22+
23+
return true;
24+
}

0 commit comments

Comments
 (0)