Palindrome Number

作者: d1497e8e780a | 来源:发表于2019-01-27 15:44 被阅读7次

    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
        }
    }
    

    相关文章

      网友评论

        本文标题:Palindrome Number

        本文链接:https://www.haomeiwen.com/subject/sxzgjqtx.html