PS/leetcode
[leetcode] 9. Palindrome Number
AlephZero
2019. 4. 28. 21:59
문제
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
풀이
음수인 경우는 무조건 false를 return한다.
양수인 경우에는 Reverse Integer를 구해서 같은지 체크한다.
Time Complexity : $O(logn)$
코드
class Solution {
public:
bool isPalindrome(int x) {
if(x<0) return false;
long long num=0, t=x;
while(t)
{
num = num*10+t%10;
t/=10;
}
return x==num;
}
};