diff --git a/missing-number/bemelon.py b/missing-number/bemelon.py new file mode 100644 index 000000000..8767b6e0a --- /dev/null +++ b/missing-number/bemelon.py @@ -0,0 +1,12 @@ +class Solution: + # Time complexity: O(n) + # Space complexity: O(1) + def missingNumber(self, nums: List[int]) -> int: + visited = 0 + for num in nums: + visited |= (1 << num) + + for i in range(len(nums) + 1): + if (not visited & (1 << i)): + return i + return -1 \ No newline at end of file diff --git a/valid-palindrome/bemelon.py b/valid-palindrome/bemelon.py new file mode 100644 index 000000000..7e5dc93ff --- /dev/null +++ b/valid-palindrome/bemelon.py @@ -0,0 +1,18 @@ +class Solution: + def isAlphaNum(self, c : str): + return 'a' <= c.lower() <= 'z' or '0' <= c <= '9' + + # Time complexity: O(n) + # Space complexity: O(1) + def isPalindrome(self, s: str) -> bool: + left, right = 0, len(s) - 1 + + while left < right: + if self.isAlphaNum(s[left]) and self.isAlphaNum(s[right]): + if s[left].lower() != s[right].lower(): + return False + left, right = left + 1, right - 1 + else: + left, right = left + (not self.isAlphaNum(s[left])), right - (not self.isAlphaNum(s[right])) + + return True \ No newline at end of file