Initial commit

This commit is contained in:
2025-05-21 14:26:13 +03:00
commit b33e3df329
11 changed files with 439 additions and 0 deletions

46
9/9.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include <iostream>
#include <vector>
namespace {
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0)
return false;
std::vector<int> 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 <gtest/gtest.h>
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);
}