import math
class Solution:
def isPalindrome(self, x: int) -> bool:
s = str(x)
l = len(s)
for i in range(l // 2):
if s[i] != s[l - 1 - i]:
return False
return True
# def isPalindrome(self, x: int) -> bool:
# s = str(x)
# l = len(s)
# if l == 2:
# return s[0] == s[1]
# is_even = l % 2 == 0
# start = 0
# end = l - 1
# if is_even:
# while start < end:
# if s[start] == s[end]:
# start += 1
# end -= 1
# else:
# return False
# else:
# middle_idx = math.ceil(l / 2)
# for i in range(middle_idx):
# if s[start] == s[end]:
# start += 1
# end -= 1
# else:
# return False
# return True'Algorithm > 문제풀이' 카테고리의 다른 글
| [leetcode]13. Roman to Integer (1) | 2026.01.04 |
|---|---|
| [leetcode] 3079. Find the Sum of Encrypted Integers - Rust (0) | 2024.05.03 |
| [leetcode] 2451. Odd String Difference - Rust (0) | 2024.05.03 |
| [leetcode] 1417. Reformat The String in C++ (0) | 2024.05.01 |
| [BOJ] 백준 16939 - 2×2×2 큐브 - Java solution (0) | 2022.11.11 |