This commit is contained in:
parent
67d21139eb
commit
c214c8dff4
13
include/s0009_palindrome_number.hpp
Normal file
13
include/s0009_palindrome_number.hpp
Normal 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
|
8
src/s0009_palindrome_number.cpp
Normal file
8
src/s0009_palindrome_number.cpp
Normal 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;
|
||||
}
|
24
tests/s0009_palindrome_number.cpp
Normal file
24
tests/s0009_palindrome_number.cpp
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user