diff --git a/include/s0009_palindrome_number.hpp b/include/s0009_palindrome_number.hpp new file mode 100644 index 0000000..4d11182 --- /dev/null +++ b/include/s0009_palindrome_number.hpp @@ -0,0 +1,13 @@ +#ifndef S0009_PALINDROME_NUMBER +#define S0009_PALINDROME_NUMBER + +#include + +using namespace std; + +class Solution { + public: + bool isPalindrome(int x); +}; + +#endif diff --git a/src/s0009_palindrome_number.cpp b/src/s0009_palindrome_number.cpp new file mode 100644 index 0000000..63a3981 --- /dev/null +++ b/src/s0009_palindrome_number.cpp @@ -0,0 +1,8 @@ +#include "s0009_palindrome_number.hpp" + +bool Solution::isPalindrome(int x) { + string s = to_string(x); + string r = s; + reverse(r.begin(), r.end()); + return s == r; +} diff --git a/tests/s0009_palindrome_number.cpp b/tests/s0009_palindrome_number.cpp new file mode 100644 index 0000000..48de79b --- /dev/null +++ b/tests/s0009_palindrome_number.cpp @@ -0,0 +1,24 @@ +#include "s0009_palindrome_number.hpp" + +#include + +TEST(Problem9, Case1) { + int i{121}; + bool o{true}; + Solution solution; + EXPECT_EQ(solution.isPalindrome(i), o); +} + +TEST(Problem9, Case2) { + int i{-121}; + bool o{false}; + Solution solution; + EXPECT_EQ(solution.isPalindrome(i), o); +} + +TEST(Problem9, Case3) { + int i{10}; + bool o{false}; + Solution solution; + EXPECT_EQ(solution.isPalindrome(i), o); +}