Skip to content

Commit 04985be

Browse files
committed
feat(math): add palindrome number checker using standard headers
1 parent 09d2cd8 commit 04985be

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

math/palindrome_number.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
/**
2+
* @file
3+
* @brief Check if a given number is a palindrome
4+
* @details
5+
* This program defines a function `is_palindrome_number()` which checks whether
6+
* a number reads the same backward as forward.
7+
* Negative numbers are treated as non-palindromic.
8+
*
9+
* @see https://en.wikipedia.org/wiki/Palindrome
10+
*/
11+
112
#include <iostream>
213
#include <string>
314
#include <vector>
415

5-
// Function to check if a number is a palindrome
16+
/**
17+
* @brief Checks if an integer is a palindrome number.
18+
* @param n The number to check.
19+
* @return `true` if `n` is a palindrome, otherwise `false`.
20+
*/
621
bool is_palindrome_number(long long n) {
722
if (n < 0)
8-
return false; // Negative numbers are not palindromes
23+
return false;
924
std::string s = std::to_string(n);
1025
int i = 0, j = static_cast<int>(s.size()) - 1;
1126
while (i < j) {
@@ -18,6 +33,9 @@ bool is_palindrome_number(long long n) {
1833
}
1934

2035
#ifdef RUN_LOCAL
36+
/**
37+
* @brief Example test cases for the palindrome number checker.
38+
*/
2139
int main() {
2240
std::vector<long long> tests = {121, -121, 10, 12321, 0};
2341
for (auto t : tests) {

0 commit comments

Comments
 (0)