Package g0001_0100.s0007_reverse_integer
Class Solution
java.lang.Object
g0001_0100.s0007_reverse_integer.Solution
7 - Reverse Integer.<p>Medium</p>
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code> <em>with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p>
<p><strong>Assume the environment does not allow you to store 64-bit integers (signed or unsigned).</strong></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> x = 123</p>
<p><strong>Output:</strong> 321</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> x = -123</p>
<p><strong>Output:</strong> -321</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> x = 120</p>
<p><strong>Output:</strong> 21</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> x = 0</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>-2<sup>31</sup> <= x <= 2<sup>31</sup> - 1</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
reverse
public int reverse(int x)
-