반응형
leetcode.com/problems/palindrome-number/
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
bool isPalindrome(int x) {
if (x < 0) return false;
int c = 1;
int t = x;
while (1) {
t /= 10;
if (t == 0) break;
c *= 10;
}
int a, b;
while (x) {
a = x / c;
b = x % 10;
if (a != b) return false;
x = (x - a * c - b)/10;
c /= 100;
if (c == 1) return true;
}
return true;
}
|
cs |
반응형
'코딩테스트 > Leetcode' 카테고리의 다른 글
Leetcode - [Easy]13. Roman to Integer (0) | 2021.03.14 |
---|---|
Leetcode - [Medium]3. Longest Substring Without Repeating Characters (0) | 2021.03.07 |
Leetcode - [Medium]2. Add Two Numbers (0) | 2021.03.04 |
Leetcode - [Easy]7. Reverse Integer (0) | 2021.03.04 |
Leetcode - [Easy]1. Two Sum (0) | 2021.03.04 |