diff --git a/number-of-1-bits/sukyoungshin.ts b/number-of-1-bits/sukyoungshin.ts new file mode 100644 index 000000000..44bc4d14a --- /dev/null +++ b/number-of-1-bits/sukyoungshin.ts @@ -0,0 +1,13 @@ +function hammingWeight(n: number): number { + let count = 0; + let num = n; + + while (num > 0) { + if (num % 2 === 1) { + count++; + } + num = Math.floor(num / 2); + } + + return count; +}; diff --git a/valid-palindrome/sukyoungshin.ts b/valid-palindrome/sukyoungshin.ts new file mode 100644 index 000000000..e2fdcfac4 --- /dev/null +++ b/valid-palindrome/sukyoungshin.ts @@ -0,0 +1,24 @@ +const alphaNumSet = new Set([..."abcdefghijklmnopqrstuvwxyz0123456789"]); + +function isPalindrome(s: string): boolean { + let normalized = ""; + + for (const characters of s) { + const lower = characters.toLowerCase(); + if (alphaNumSet.has(lower)) { + normalized += lower; + } + } + + let left = 0; + let right = normalized.length - 1; + while (left < right) { + if (normalized[left] !== normalized[right]) { + return false; + } + left++; + right--; + } + + return true; +}