Palindromic Numbers¶
Table of Contents¶
- 9. Palindrome Number (Easy)
- 2396. Strictly Palindromic Number (Medium)
- 2217. Find Palindrome With Fixed Length (Medium)
- 866. Prime Palindrome (Medium)
- 2967. Minimum Cost to Make Array Equalindromic (Medium)
- 906. Super Palindromes (Hard)
- 2081. Sum of k-Mirror Numbers (Hard)
- 3260. Find the Largest Palindrome Divisible by K (Hard)
- 3272. Find the Count of Good Integers (Hard)
- 564. Find the Closest Palindrome (Hard)
- 479. Largest Palindrome Product (Hard)
9. Palindrome Number¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: math
- Return true if the given number is a palindrome. Otherwise, return false.
9. Palindrome Number - Python Solution
# Reverse
def isPalindromeReverse(x: int) -> bool:
if x < 0:
return False
return str(x) == str(x)[::-1]
# Left Right Pointers
def isPalindromeLR(x: int) -> bool:
if x < 0:
return False
x = list(str(x)) # 121 -> ['1', '2', '1']
left, right = 0, len(x) - 1
while left < right:
if x[left] != x[right]:
return False
left += 1
right -= 1
return True
# |------------|------- |---------|
# | Approach | Time | Space |
# |------------|--------|---------|
# | Reverse | O(N) | O(N) |
# | Left Right | O(N) | O(1) |
# |------------|--------|---------|
x = 121
print(isPalindromeReverse(x)) # True
print(isPalindromeLR(x)) # True
2396. Strictly Palindromic Number¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, two pointers, brainteaser
2217. Find Palindrome With Fixed Length¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math
866. Prime Palindrome¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, number theory
2967. Minimum Cost to Make Array Equalindromic¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, binary search, greedy, sorting
906. Super Palindromes¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, string, enumeration
2081. Sum of k-Mirror Numbers¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, enumeration
3260. Find the Largest Palindrome Divisible by K¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, string, dynamic programming, greedy, number theory
3272. Find the Count of Good Integers¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: hash table, math, combinatorics, enumeration
564. Find the Closest Palindrome¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, string
479. Largest Palindrome Product¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, enumeration