
g0001_0100.s0007_reverse_integer.solution.rb Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
# #Medium #Top_Interview_Questions #Math #Udemy_Integers
# #2023_11_14_Time_58_ms_(75.27%)_Space_211.2_MB_(14.29%)
# @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
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy