fork download
  1. class Solution:
  2. def isPalindrome(self, s: str) -> bool:
  3. i = 0
  4. j = len(s) - 1
  5. while i <= j and i < len(s) - 1 and j >= 0:
  6. if not (s[i].isalpha() or s[i].isdigit()):
  7. i+=1
  8. continue
  9. if not (s[j].isalpha() or s[j].isdigit()):
  10. j-=1
  11. continue
  12. if s[i].lower() != s[j].lower():
  13. return False
  14. else :
  15. i+=1
  16. j-=1
  17.  
  18.  
  19.  
  20. return True
Success #stdin #stdout 0.13s 14120KB
stdin
Standard input is empty
stdout
Standard output is empty