7. Reverse Integer
Input: 123
Output: 321Input: -123
Output: -321Input: 120
Output: 21# @param {Integer} x
# @return {Integer}
def reverse(x)
new_a = x.to_s.reverse.to_i
if x >= 0
new_a < (2**31 - 1) ? new_a : 0
else
-new_a > (-2)**31 ? -new_a : 0
end
endLast updated