Wen LEETCODE has defind d typ as INT,then hw in world can they give an input greatr than d range of INT!!


  • 1
    A
    class Solution {
    public:
        long long int reverse(long long int x) {
            
            long long int q = x, r = 0, sum = 0, flag = 0;
            
            if(q < 9 && q>= 0)
                return q;
            else {
                if(q<0){
                    flag = 1;
                    q = -q;
                }
                while(q > 9){
                    
                    r = q % 10;
                    q = q/10;
                    sum = sum*10 + r;
                }
                sum = sum*10 + q;
                if(flag == 1)
                    return -sum;
                else
                    return sum;
            }
        }
    };

Log in to reply
 

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