09 · Math & Number Theory

#7 Reverse Integer

Mediumsolve on LeetCode ↗

frequently reported atBloombergAppleGoogleMicrosoftAmazonTCS

the problem

In plain words

You get a signed 32-bit int x. Return x with its digits in reverse order, keeping the sign. If the reversed value does not fit in a signed 32-bit int (−2³¹ to 2³¹ − 1), return 0. Pretend you cannot store 64-bit values.

in x = 123

out 321

in x = -123

out -321

in x = 120

out 21

The trailing zero becomes a leading zero and disappears.

  • −2³¹ ≤ x ≤ 2³¹ − 1

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #9
      Palindrome Number
      Easyin Math & Numbers
    2. #66
      Plus One
      Easyin Math & Numbers