Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions number-of-1-bits/sooooo-an.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function hammingWeight(n: number): number {
return n.toString(2).replace(/0/g, "").length;
}
20 changes: 20 additions & 0 deletions valid-palindrome/sooooo-an.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace 메소드를 써서 구현할 수도 있군요 👍 코드 잘 봤습니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function isPalindrome(s: string): boolean {
const cleanString = s
.toLowerCase()
.replace(/\s+/g, "")
.replace(/[^a-z0-9]/g, "");

let left = 0;
let right = cleanString.length - 1;

while (left < right) {
if (cleanString[left] !== cleanString[right]) {
return false;
}

left++;
right--;
}

return true;
}