728x90

9. Palindrome Number
Solved
Easy
Topics
Companies
Hint
Given an integer x, return true if x is a
palindrome
, and false otherwise.
Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Constraints:
- -231 <= x <= 231 - 1
Follow up: Could you solve it without converting the integer to a string?
Accepted
3.6M
Submissions
6.6M
Acceptance Rate
54.4%
나의 풀이
class Solution:
def isPalindrome(self, x: int) -> bool:
xstr = list(str(x))
# 정수 x를 문자열로 바꾼 리스트를 만든다.
return xstr == xstr[::-1]
# 이 때 xstr과 xstr[::-1](xstr을 뒤집은 리스트)가 같으면 True, 다르면 False를 리턴한다.728x90
'Coding Test' 카테고리의 다른 글
| [CT] 프로그래머스 원소들의 곱과 합 Python3 ver. (0) | 2023.09.16 |
|---|---|
| [CT] 프로그래머스 배열만들기1 Python3 ver. (0) | 2023.09.14 |
| [CT] 프로그래머스 첫 번째로 나오는 음수 Javascript ver. (0) | 2023.09.12 |
| [CT] 프로그래머스 첫 번째로 나오는 음수 Python3 ver. (0) | 2023.09.12 |
| [CT] 프로그래머스 같은 숫자는 싫어 Javascript ver. (0) | 2023.09.06 |