g0001_0100.s0009_palindrome_number.Solution.cpp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
The newest version!
// #Easy #Math #Udemy_Integers #2024_05_23_Time_0_ms_(100.00%)_Space_8.2_MB_(48.20%)
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0) {
return false;
}
int rev = 0;
int localX = x;
while (localX > 0) {
if (rev > (INT_MAX - localX % 10) / 10) {
return false;
}
rev = rev * 10 + localX % 10;
localX /= 10;
}
return rev == x;
}
};
© 2015 - 2025 Weber Informatics LLC | Privacy Policy