Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEMELON] Week 4 #431

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 12 additions & 0 deletions missing-number/bemelon.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions valid-palindrome/bemelon.py
Original file line number Diff line number Diff line change
@@ -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
Loading