update 7
This commit is contained in:
parent
305883a1e4
commit
4c93cad586
18
leetcode/7.py
Normal file
18
leetcode/7.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Reverse Integer
|
||||||
|
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def reverse(self, x: int) -> int:
|
||||||
|
str_x = str(x)
|
||||||
|
reverse_str_x = str_x[::-1]
|
||||||
|
if reverse_str_x[-1] == "-":
|
||||||
|
reverse_str_x = "-" + reverse_str_x[:-1]
|
||||||
|
return int(reverse_str_x)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
x = 120
|
||||||
|
rev_x = Solution().reverse(x)
|
||||||
|
print(rev_x)
|
||||||
|
x = -123
|
||||||
|
print(Solution().reverse(x))
|
Loading…
x
Reference in New Issue
Block a user