Skip to content

Commit 3380c30

Browse files
authored
Update README_EN.md
1 parent b50b69d commit 3380c30

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

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

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

243243
#### C
244244

245-
```C
245+
```c
246246
bool isPalindrome(int x) {
247-
if (x < 0)
247+
if (x < 0 || (x != 0 && x % 10 == 0)) {
248248
return false;
249-
int original = x;
250-
int reversed = 0;
251-
while (x != 0) {
252-
int digit = x % 10;
253-
if (reversed > (2147483647 - digit) / 10)
254-
return false;
255-
reversed = reversed * 10 + digit;
249+
}
250+
251+
int y = 0;
252+
while (y < x) {
253+
y = y * 10 + x % 10;
256254
x /= 10;
257255
}
258-
return original == reversed;
259-
}
260256

257+
return (x == y || x == y / 10);
258+
}
261259
```
262260
263261
<!-- tabs:end -->

0 commit comments

Comments
 (0)