欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Palindrome Number

程序员文章站 2024-03-22 14:26:04
...

Swift 4.2

class Solution {
func isPalindrome(_ x: Int) -> Bool {
      if x < 0 {
        return false
      }
      var originX = x
      var reverserdX = 0
      while originX > 9 {
        reverserdX = (reverserdX + originX  % 10)  * 10
        originX  = originX / 10
      }
      reverserdX +=  originX  % 10 
      return x == reverserdX
    }
}