[Leetcode] 9. Palindrome number

Source: Internet
Author: User

#include <stdio.h>#include<stdbool.h>#include<math.h>//9. Palindrome Number//determine whether an integer is a palindrome. Do this without extra space.// https://leetcode.com/problems/palindrome-number///algorithm://get reverse of x = X '//check whether x = = X '//If yes, return True//else, return false//assume x >= 0//assume no ' + ' or '- ' sign at front//Assume no space//base Case:x <, return trueBOOLIspalindrome (intx) {//Base Case    if(X <0)return false;//Negative number is not palindromic    if(X <Ten)return true;//Single digit is palindrome//Get Reverse of x    inty =0, n =x;  while(n) {y= y *Ten+ n%Ten; N/=Ten; }    //if original x equals to their reverse, it is palindrome    if(x = = y)return true; return false;}intMain () {intx =-2147447412; Char*result = ispalindrome (x) >0?"true":"false"; printf ("*%d* is palindrome:%s\n", x, result);}

[Leetcode] 9. Palindrome number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.