123456789101112131415 |
- /* Write a function that returns true if a number is a palindrome.
- */
- bool isPalindrome(int n) {
- //std::string x = std::to_string(n);
- //std::reverse(x.begin(),x.end());
- //return std::to_string(n) == x;
- // convert int to string
- std::string newN = std::to_string(n);
- for(int i=0;i<newN.size();i++){
- if(newN[i]!=newN[newN.size()-1-i]){
- return false;
- }
- }
- return true;
- }
|