Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
366 B
1
Indexable
class Solution {
public:
int reverse(int x) {
    long r=0;      // decleare r
    while(x){
        r=r*10+x%10; // find remainder and add its to r
        x=x/10;     // Update the value of x
    }
    if(r>INT_MAX || r<INT_MIN) return 0; // check range if r is outside the range then return 0
    return int(r);  // if r in the 32 bit range then return r
    }
};
Leave a Comment