C++ 2 Solutions - Palindrome Number - LeetCode
Sun Jan 22 2023 04:19:31 GMT+0000 (Coordinated Universal Time)
Saved by
@sigmah197
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
class Solution {
public:
bool isPalindrome(int x) {
string str = to_string(x);
for(int i = 0; i < str.length() / 2; i++){
if(str[i] != str[str.length() - i - 1]) return false;
}
return true;
}
};
int main()
{
Solution a;
int x;
cout<< "enter a number";
cin>>x;
cout<<a.isPalindrome(x);
}
content_copyCOPY
https://leetcode.com/problems/palindrome-number/submissions/882363724/
Comments