"title"
are you familiar with palindrome? A string from the front and back look if the same, is a palindrome string, such as "Shanghai Water from the Sea" is a palindrome string. Now our problem comes, to think of a number as a string and ask if it is a palindrome number? The higher the score, the lower the time complexity and the less space complexity.
C + +:
bool Ispalindromenumber (long num);
Java:
boolean ispalindromenumber (Long num);
"Code"
#include <iostream>using namespace Std;bool ispalindromenumber (Long num) { long reversenum = 0; Long temp = num; while (Temp > 0) { reversenum = reversenum * + temp%; Temp/=; } if (reversenum = = num) { return true; } else{ return false; }} int main () { long num; cin>>num; BOOL result = Ispalindromenumber (num); if (result) { cout<<num<< "is a palindrome number" <<endl; } else{ cout<<num<< "is not a palindrome number" <<endl; } return 0;}
"Expand 1" string judging palindrome
BOOL Ispalindromenumber (string num) { int len = Num.length (); for (int i = 0;i < len/2;i++) { if (num[i]! = Num[len-1-i]) { return false; } } return true;}
BOOL Ispalindromenumber (string num) { int len = Num.length (); for (int i = 0,j = Len-1;i < j;i++,j--) { if (num[i]! = Num[j]) { return false; } } return true;}
Ask about Palindrome pen questions, you can send me a link, thank you ...
[Millet]2015 Millet School recruit of palindrome number judgment