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
}
}
网友评论