Last active
December 16, 2020 09:55
-
-
Save anbento0490/f9af3de342368a0f606403d22af83306 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given an integer, return the integer with reversed digits. | |
# Note: The integer could be either positive or negative. | |
def solution(x): | |
string = str(x) | |
if string[0] == '-': | |
return int('-'+string[:0:-1]) | |
else: | |
return int(string[::-1]) | |
print(solution(-231)) | |
print(solution(345)) |
gunesmes
commented
Oct 18, 2020
Very helpful on algorithm tests. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment