#include #include namespace { class Solution { public: bool isPalindrome(int x) { if (x < 0) return false; std::vector v; v.reserve(32); while (x > 0) { int z = x % 10; x = x / 10; v.emplace_back(z); } for (size_t i = 0; i < v.size(); ++i) { if (v[i] != v[v.size() - 1 - i]) return false; } return true; } }; }; #include Solution s; TEST(P9, 1) { EXPECT_EQ(s.isPalindrome(121), true); } TEST(P9, 2) { EXPECT_EQ(s.isPalindrome(-121), false); } TEST(P9, 3) { EXPECT_EQ(s.isPalindrome(10), false); }