복's

[ LeetCode - 9 ] Palindrome Number 본문

알고리즘/LeetCode

[ LeetCode - 9 ] Palindrome Number

나복이 2023. 10. 29. 21:47
728x90

https://leetcode.com/problems/palindrome-number/

 

Palindrome Number - LeetCode

Can you solve this real interview question? Palindrome Number - 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. Ex

leetcode.com

 

문자열 문제로 팰린드롬의 조건만 확인하면 되는문제로 나는 문자열(orginal)과 뒤집어진 문자열(reversed)를 비교해서 풀었다.

 

코드는 간단하다.


[ 📌 코드 - Python ]

class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x < 0:
            return False

        org_list = list(map(int, str(x)))

        return org_list == org_list[::-1]

[ 📌 결과 ]

[ Result ]

728x90