Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.
(翻转一个有符号整形数值字符串)
Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: \([−2^{31}, 2^{31} − 1]\). For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
Example:
1. 字符串翻转
1 | class Solution: |
注:超过有符号整形的范围时需要返回0。另外string[::-1]
也可以直接实现字符串的翻转。
2. 整形翻转
1 | class Solution: |