Reverse Integer

Easy Solved

Description

Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-2³¹, 2³¹ - 1], return 0.

Example 1:

Input: x = 123

Output: 321

Example 2:

Input: x = -123

Output: -321

Example 3:

Input: x = 120

Output: 21

Note:

Runner reads a single integer from stdin (e.g. 123) and expects a single integer printed to stdout (e.g. 321).

Your Submissions

No submissions yet.

Discuss

Share approaches: string-reverse, math-based reversal, overflow checks.

Test Cases

Test Case 1
Test Case 2
Test Case 3