fork download
  1. # your code goes here
  2. class Solution:
  3. def validPalindrome(self, s: str) -> bool:
  4.  
  5. n = len(s)
  6. count = 0
  7. i, j = 0, n - 1
  8.  
  9. if n == 2: return True
  10. if n == 3: return True if s[i] == s[j] else False
  11.  
  12. while i < j:
  13. # print(f"before condition:{s[i]}, {s[j]}")
  14. if count < 2 and s[i] == s[j]:
  15. i += 1
  16. j -= 1
  17. # print(f"from first if i: {i}, j: {j}, s: {s}")
  18. # print(f"{s[i]}, {s[j]}")
  19.  
  20. else:
  21. count += 1
  22. if count == 2: return False
  23. print(count)
  24.  
  25. if s[i] == s[j-1]:
  26. j -= 1
  27. # print(f"from j movement if i: {i}, j: {j}, s: {s} ")
  28. # print(f"{s[i]}, {s[j]}")
  29.  
  30. elif s[i+1] == s[j]:
  31. i += 1
  32. # print(f"from i movement if i: {i}, j: {j}, s: {s} ")
  33. # print(f"{s[i]}, {s[j]}")
  34.  
  35.  
  36. return True
  37.  
Success #stdin #stdout 0.09s 14176KB
stdin
Standard input is empty
stdout
Standard output is empty