def isPalindrome(s):
if not s:
return True
st = "".join(char for char in s if char.alphanum()).lower()
return st == st[::-1]
From what I understand, the reverse slicing [::-1] is O(n). However I'm not sure about join()'s time complexity, does it create a new string every time and iterate over it? Wouldn't that make it O(n^2)?