Search

Imran Pollob
Imran Pollob
  • Home
  • Contact
  • Blog++
    Blog Data Structures & Algorithms Leetcode solution Hackerrank solution Codesignal solution
  • Light Dark
  • LEETCODE SOLUTIONS
  • 1920 - Build Array from Permutation
  • 1929 - Concatenation of Array
  • 1480 - Running Sum of 1d Array
  • 28 - Implement strStr()
  • 7 - Reverse Integer
  • 9 - Palindrome Number
  • 283 - Move Zeros
  • 485 - Max Consecutive Ones
  • Contents
  1. Home
  2. LEETCODE SOLUTIONS
  3. 7 - Reverse Integer

Leetcode 7 - Reverse Integer solution

Problem link

Solution:

class Solution {
    public int reverse(int x) {
        int rev = 0;
        
        while(x != 0){
            if(rev > Integer.MAX_VALUE / 10 || rev < Integer.MIN_VALUE / 10)
                return 0;
            rev = rev * 10 + x % 10;
            x = x / 10;
        }
        
        return rev;
    }
}
Previous
Leetcode 28 - Implement strStr() solution
Next
Leetcode 9 - Palindrome Number solution

Last updated on Dec 20, 2021

© 2022 Imran Pollob

Published with Wowchemy — the free, open source website builder that empowers creators.

Cite
Copy Download