File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+
4+ class Solution :
5+ # Time: O(n)
6+ # Space: O(1)
7+ def missingNumber (self , nums : List [int ]) -> int :
8+ n = len (nums )
9+ # MissingNumber = (Sum of 1, 2, ..., n) - Sum of nums)
10+ # Time: O(n)
11+ return n * (n + 1 ) // 2 - sum (nums )
Original file line number Diff line number Diff line change 1+ import re
2+
3+
4+ class Solution :
5+ # Time: O(n)
6+ # Space: O(1)
7+ def isPalindrome (self , s : str ) -> bool :
8+ # 1. Convert string
9+ # Time: O(n)
10+ # Space: O(n) since re.sub() will internally use a new string of length n.
11+ s = re .sub ('[^a-z0-9]' , '' , s .lower ())
12+ length = len (s )
13+ # 2. Check if the string reads the same forward and backward, one by one.
14+ # Time: O(n)
15+ # Space: O(1)
16+ for i in range (length ):
17+ if (s [i ] != s [length - 1 - i ]):
18+ return False
19+ return True
You can’t perform that action at this time.
0 commit comments