We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a3ce611 commit 41d98cdCopy full SHA for 41d98cd
PalindromeNumber.cpp
@@ -0,0 +1,40 @@
1
+class Solution {
2
+public:
3
+ bool isPalindrome(int x) {
4
+ if(x<0){
5
+ return false;
6
+ }
7
+ string s="";
8
+ while(x>0) {
9
+ s.push_back(x%10);
10
+ x /=10;
11
12
+ string rev=s;
13
+ reverse(s.begin(),s.end());
14
+ if(s.compare(rev) == 0) {
15
+ return true;
16
17
18
19
+};
20
+
21
+int stringToInteger(string input) {
22
+ return stoi(input);
23
+}
24
25
+string boolToString(bool input) {
26
+ return input ? "True" : "False";
27
28
29
+int main() {
30
+ string line;
31
+ while (getline(cin, line)) {
32
+ int x = stringToInteger(line);
33
34
+ bool ret = Solution().isPalindrome(x);
35
36
+ string out = boolToString(ret);
37
+ cout << out << endl;
38
39
+ return 0;
40
0 commit comments