forked from fullstackmeetups/coding-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
27 lines (20 loc) · 734 Bytes
/
Copy pathscript.py
File metadata and controls
27 lines (20 loc) · 734 Bytes
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
"""This problem was asked by Palantir.
Write a program that checks whether an integer is a palindrome.
For example, 121 is a palindrome, as well as 888. 678 is not a palindrome.
Do not convert the integer into a string."""
import math
def check_palindrome(num):
# number length
digits = int(math.log10(num)) + 1
numbers = []
for idx in range(1, digits + 1):
curr_digit = num // 10 ** (int(math.log(num, 10)) - idx + 1) % 10
numbers.append(curr_digit)
for idx in range(len(numbers)):
if numbers[idx] != numbers[-1 - idx]:
return False
return True
print(check_palindrome(89798))
print(check_palindrome(781))
print(check_palindrome(121))
print(check_palindrome(678))