Accepted Ruby Solution One Line


  • 0
    I
    # @param {Integer} x
    # @return {Boolean}
    def is_palindrome(x)
        return x.to_s == x.to_s.reverse
    end
    
    # def is_palindrome(x)
    #     if ((x.nil?) || !([Integer,Float,Fixnum].include? x.class))
    #         return false
    #     end
    #     if (x.to_s.size == 1)
    #         return true
    #     end
    #     head = 0
    #     tail = x.to_s.size - 1
    #     while (head < tail) do
    #         if (x.to_s[head] != x.to_s[tail])
    #             return false
    #         end
    #         head = head + 1
    #         tail = tail - 1
    #     end
    #     return true
    # end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.