-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome Number.py
36 lines (27 loc) · 985 Bytes
/
Palindrome Number.py
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
32
33
34
35
36
"""
Determine whether an integer is a palindrome. Do this without extra space.
"""
def isPalindrome(x):
"""
:type x: int
:rtype: bool
"""
#convert integer to string
xString = str(x)
#create a reverse duplicate of the new string
xReverse = xString[::-1]
"""
Discovered this capability of slices when looking to see if python had a reverse string function
This is extended slice syntax. It works by doing [begin:end:step]
- by leaving begin and end off and specifying a step of -1, it reverses a string.
"""
if xString == xReverse:
return(True)
else:
return(False)
testInteger = 123456
print("Checking for Palindrome numbers: ", testInteger," : ", isPalindrome(testInteger))
testInteger = 12345654321
print("Checking for Palindrome numbers: ", testInteger," : ", isPalindrome(testInteger))
testInteger = 78900987
print("Checking for Palindrome numbers: ", testInteger," : ", isPalindrome(testInteger))