Skip to content

Commit c51b5e6

Browse files
authored
[LEET] Palindrome Number (Easy)
1 parent 8355304 commit c51b5e6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

박예진/4주차/260120.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(int x) {
4+
// 음수 || x 일의 자리가 0일 경우
5+
if (x < 0 || (x != 0 && x % 10 == 0)) return false;
6+
7+
int reversed = 0;
8+
while(x > reversed) {
9+
reversed = reversed * 10 + x % 10;
10+
x /= 10;
11+
}
12+
13+
// 최종 결과
14+
if (x == reversed || x == reversed / 10) return true;
15+
else return false;
16+
}
17+
};

0 commit comments

Comments
 (0)