Skip to content
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
11 changes: 11 additions & 0 deletions missing-number/joon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import List


class Solution:
# Time: O(n)
# Space: O(1)
def missingNumber(self, nums: List[int]) -> int:
n = len(nums)
# MissingNumber = (Sum of 1, 2, ..., n) - Sum of nums)
# Time: O(n)
return n * (n + 1) // 2 - sum(nums)
19 changes: 19 additions & 0 deletions valid-palindrome/joon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import re


class Solution:
# Time: O(n)
# Space: O(1)
def isPalindrome(self, s: str) -> bool:
# 1. Convert string
# Time: O(n)
# Space: O(n) since re.sub() will internally use a new string of length n.
s = re.sub('[^a-z0-9]', '', s.lower())
length = len(s)
# 2. Check if the string reads the same forward and backward, one by one.
# Time: O(n)
# Space: O(1)
for i in range(length):
if (s[i] != s[length - 1 - i]):
return False
return True