https://leetcode.com/problems/strictly-palindromic-number/description/
Strictly Palindromic Number - LeetCode
Strictly Palindromic Number - 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 f
leetcode.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
def base_n(number, base):
based_number = ''
while number > 0:
based_number += str(number % base)
number //= base
if based_number == based_number[::-1]:
return True
else:
return False
class Solution:
def isStrictlyPalindromic(self, n: int) -> bool:
answer = True
for base in range(2, n - 1):
if not base_n(n, base):
answer = False
break
return answer
|
cs |
진법 변환하는 함수를 만들고, 그 결과가 palindromic 한지 출력하는 문제입니다
It is a problem to create a function that converts base and outputs whether the result is palindromic.
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2433. Find The Original Array of Prefix Xor (0) | 2023.01.27 |
---|---|
leetcode 2545. Sort the Students by Their Kth Score (0) | 2023.01.27 |
leetcode 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers (0) | 2023.01.26 |
codeforces 50A - Domino piling (0) | 2023.01.25 |
codeforces 1772A - A+B? (0) | 2023.01.25 |
댓글