-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem9.cpp
More file actions
34 lines (34 loc) · 732 Bytes
/
problem9.cpp
File metadata and controls
34 lines (34 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution
{
public:
bool isPalindrome(int x)
{
if (x < 0)
{
return false;
}
auto s = std::to_string(x);
if (s.length() == 1)
{
return true;
}
while (s.length() > 0)
{
if (s.length() == 3 && s.at(0) == s.at(2))
{
return true;
}
else if (s.length() == 3 && s.at(0) != s.at(2))
{
return false;
}
if (s.at(0) != s.at(s.length() - 1))
{
return false;
}
s = s.substr(1, s.length() - 2);
std::cout << s << " ";
}
return true;
}
};