You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.
/*
* @lc app=leetcode id=9 lang=cpp
*
* [9] Palindrome Number
*
* https://leetcode.com/problems/palindrome-number/description/
*
* algorithms
* Easy (44.86%)
* Likes: 1620
* Dislikes: 1373
* Total Accepted: 674.1K
* Total Submissions: 1.5M
* Testcase Example: '121'
*
* Determine whether an integer is a palindrome. An integer is a palindrome
* when it reads the same backward as forward.
*
* Example 1:
*
*
* Input: 121
* Output: true
*
*
* Example 2:
*
*
* Input: -121
* Output: false
* Explanation: From left to right, it reads -121. From right to left, it
* becomes 121-. Therefore it is not a palindrome.
*
*
* Example 3:
*
*
* Input: 10
* Output: false
* Explanation: Reads 01 from right to left. Therefore it is not a
* palindrome.
*
*
* Follow up:
*
* Coud you solve it without converting the integer to a string?
*
*/
class Solution
{
public :
bool isPalindrome ( int x )
{
char buf [ 20 ] ;
sprintf ( buf , " %d " , x ) ;
for ( int i = 0 , j = strlen ( buf ) ; i < j ; )
if ( buf [ i + + ] ! = buf [ - - j ] )
return false ;
return true ;
}
} ;