code.cpp 382 B

123456789101112131415
  1. /* Write a function that returns true if a number is a palindrome.
  2. */
  3. bool isPalindrome(int n) {
  4. //std::string x = std::to_string(n);
  5. //std::reverse(x.begin(),x.end());
  6. //return std::to_string(n) == x;
  7. // convert int to string
  8. std::string newN = std::to_string(n);
  9. for(int i=0;i<newN.size();i++){
  10. if(newN[i]!=newN[newN.size()-1-i]){
  11. return false;
  12. }
  13. }
  14. return true;
  15. }