Strictly Palindromic Number — LeetCode 2396 Python Solution
- Problem
- #2396
- Pattern
- Two Pointers
- Reading time
- 2 min
- Source
- leetcode.com
The problem
An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic. Given an integer n, return true if n is strictly palindromic and false otherwise.
Example
- Input
- n = 9
- Output
- false
- Explanation
- In base 2: 9 = 1001 (base 2), which is palindromic.
Python solution
class Solution:
def isStrictlyPalindromic(self, n: int) -> bool:
return FalseComplexity
| Measure | Complexity |
|---|---|
| Time | O(1) |
| Space | O(1) auxiliary |
Pattern: Two Pointers
Use the order already in the input to discard half the search space at every step. LeetCode 2396. Strictly Palindromic Number is filed here because LeetCode tags it Two Pointers, which is the vocabulary this hub collects.
The two pointers guide has the Python template for the pattern and the 201 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2396. Strictly Palindromic Number?
- LeetCode 2396. Strictly Palindromic Number is rated Medium on LeetCode.
- What is the time complexity of LeetCode 2396. Strictly Palindromic Number?
- The Python solution on this page runs in O(1).
- What is the space complexity of LeetCode 2396. Strictly Palindromic Number?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2396. Strictly Palindromic Number cover?
- LeetCode 2396. Strictly Palindromic Number is tagged Brainteaser, Math and Two Pointers on LeetCode.