Skip to content

Commit

Permalink
Create 0009-palindrome-number.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
AP-Repositories authored Dec 30, 2022
1 parent 2d0e0cc commit 7e27c99
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cpp/0009-palindrome-number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;

long div = 1;
while(x >= 10 * div)
div *= 10;

while(x) {
int right = x % 10;
int left = x / div;

if(left != right) return false;

x = (x % div) / 10;
div = div / 100;
}
return true;
}
};

0 comments on commit 7e27c99

Please sign in to comment.