s0009
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Sainnhe Park 2022-11-02 22:20:09 +08:00
parent 67d21139eb
commit c214c8dff4
3 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,13 @@
#ifndef S0009_PALINDROME_NUMBER
#define S0009_PALINDROME_NUMBER
#include <string>
using namespace std;
class Solution {
public:
bool isPalindrome(int x);
};
#endif

View File

@ -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;
}

View File

@ -0,0 +1,24 @@
#include "s0009_palindrome_number.hpp"
#include <gtest/gtest.h>
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);
}