Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 |
| 31 |
Tags
- 자료구조
- Data_Structure
- Python
- adaptive remeshing
- 티스토리챌린지
- mysql
- GNN
- 데베
- 데이터
- 컴퓨터공학
- 컴퓨터사이언스
- CNN
- 오블완
- coding
- 코딩테스트
- LeetCode
- Database
- meshgraphnet
- DS
- code
- 개발자
- Mesh
- 데이터베이스
- 대학생
- 코테
- SQL
- db
- CS
- sort
- Leet Code
Archives
- Today
- Total
sy1214ei 님의 블로그
[Leet Code] 9. Palindrome Number - Python 본문
https://leetcode.com/problems/palindrome-number/description/
Level : Easy
Topic : Math
class Solution:
def isPalindrome(self, x: int) -> bool:
# 음수라면 False
# 0이라면 true
# 양수라면
# 1. 한자리수 -> true
# 2. not 한자리수
# n = len(str(x))//2 -> 반복문을 n번 돌며 앞뒤가 다르면 false 같으면 반복문 계속돌기
if x < 0 : return False
#elif x == 0 : return True
#elif len(str(x)) == 1: return True
else:
x = str(x)
n = len(x) // 2
j = len(x)-1
for i in range(n):
if x[i] != x[j]: return False
j -= 1
return True
# Time Complexity : O(n/2) = O(n)
# Space Complextiy : O(1)

'[Coding]' 카테고리의 다른 글
| [Leet Code] 409. Longest Palindrome - Python (2) | 2024.12.04 |
|---|---|
| [Leet Code] 1. Two Sum - Python (0) | 2024.12.03 |
| [Leet Code] 21. Merge Two Sorted Lists - Python (7) | 2024.11.29 |
| [Leet Code] 645. Set Mismatch - Python (0) | 2024.11.28 |
| [Leet Code] 58. Length of Last Word - Python (4) | 2024.11.26 |