Reverse Integer Easy Solution in C++


  • 0
    X
    class Solution {
    public:
    	static int reverse(int x) {
    		long long result = 0;
    		while (x != 0) {
    			int y = x % 10;
    			x /= 10;
    			result = result * 10 + y;
    		}
    		return (result > INT32_MAX || result <= INT32_MIN) ? 0 : result;
    	}
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.