Playing Hacks and Stuffs!
array[left] != array[right]
Solve Script: link
Ehhhh it isn’t optimized
After submitting the solution and looking at other people solution I saw an interesting approach:
Here’s the approach:
The person made use of isalnum()
which I didn’t know existed (this would have made my condition check a bit faster!) also instead of using like linear search approach he made use of Not ~
operator
Operator ~
is the bitwise NOT
operator (~x == -x-1 => ~0 == -1 => ~1 == -2 and etc)
, which expects just one argument. It performs logical negation on a given number by flipping all of its bits:
Here’s the script
class Solution:
def isPalindrome(self, s: str) -> bool:
s = [c.lower() for c in s if c.isalnum()]
return all (s[i] == s[~i] for i in range(len(s)//2))
Running it works
Compared to mine in terms of space complexity, mine is better but in terms of time complexity that one is better