Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Runtime: 142 ms
- #include <iostream>
- using namespace std;
- class Solution {
- public:
- bool isPalindrome(int x) {
- if (x < 0)
- return false;
- int mainCopy = x, rev = 0;
- while (x != 0)
- {
- rev *= 10;
- rev += (x % 10);
- x /= 10;
- }
- return (mainCopy == rev);
- }
- };
- int main(void)
- {
- Solution s;
- int num = 2112; // change the number from here
- if (s.isPalindrome(num))
- {
- cout << "\nPalindrome..!\n\n";
- }
- else
- {
- cout << "\nNot Palindrome..!\n\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment