美文网首页leetcode --- js版本
leetcode-Easy-第3期:isPalindrome(回

leetcode-Easy-第3期:isPalindrome(回

作者: 石头说钱 | 来源:发表于2019-02-25 23:20 被阅读2次

    判断是否为回文

    • Example 1:
    Input: 121
    Output: true
    
    
    • Example 2:
    Input: -121 
    Output: false
    从右到左是:121- (不等于-121)
    
    • Example 3:
    Input: 10
    Output: false
    从右到左是:01 (不等于10)
    
    解法
    var isPalindrome = function(x) {
      // 输入数字反转,返回string类型
      let res = String(x).split('').reverse().join('')
      if(x === Number(res){
        return true
      }
      return false
    };
    
    

    相关文章

      网友评论

        本文标题:leetcode-Easy-第3期:isPalindrome(回

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