Skip to content

Commit bf75d80

Browse files
authored
Merge pull request #2224 from Ykhan799/main
Create: 0009-palindrome-number.c
2 parents 9d18d12 + 8ae9c32 commit bf75d80

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

c/0009-palindrome-number.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
bool isPalindrome(int x){
2+
if (x < 0) {
3+
return false;
4+
}
5+
long div = 1;
6+
while (x >= 10 * div) {
7+
div *= 10;
8+
}
9+
10+
while (x) {
11+
int right = x % 10;
12+
int left = x / div;
13+
14+
if (left != right) {
15+
return false;
16+
}
17+
18+
x = (x % div) / 10;
19+
div /= 100;
20+
}
21+
22+
return true;
23+
}

0 commit comments

Comments
 (0)