Skip to content

Commit b50b69d

Browse files
authored
Update README.md
1 parent 63be5c0 commit b50b69d

File tree

1 file changed

+9
-11
lines changed
  • solution/0000-0099/0009.Palindrome Number

1 file changed

+9
-11
lines changed

solution/0000-0099/0009.Palindrome Number/README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,20 @@ class Solution {
250250

251251
#### C
252252

253-
```C
253+
```c
254254
bool isPalindrome(int x) {
255-
if (x < 0)
255+
if (x < 0 || (x != 0 && x % 10 == 0)) {
256256
return false;
257-
int original = x;
258-
int reversed = 0;
259-
while (x != 0) {
260-
int digit = x % 10;
261-
if (reversed > (2147483647 - digit) / 10)
262-
return false;
263-
reversed = reversed * 10 + digit;
257+
}
258+
259+
int y = 0;
260+
while (y < x) {
261+
y = y * 10 + x % 10;
264262
x /= 10;
265263
}
266-
return original == reversed;
267-
}
268264

265+
return (x == y || x == y / 10);
266+
}
269267
```
270268
271269
<!-- tabs:end -->

0 commit comments

Comments
 (0)