当前位置:   article > 正文

Leetcode 9. 回文数 Palindrome Number - Python 双指针法_回文数python双指针

回文数python双指针
  1. class Solution:
  2. def isPalindrome(self, x: int) -> bool:
  3. to_string = str(x)
  4. i = 0
  5. q = len(to_string)-1
  6. front = to_string[i]
  7. rear = to_string[q]
  8. while front == rear:
  9. if i==q or abs(i-q)==1:
  10. return True
  11. i += 1
  12. q -= 1
  13. front = to_string[i]
  14. rear = to_string[q]
  15. return False

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号