Share my cpp solution


  • 1
    Z
    class Solution {
    public:
    int reverse(int x) {
        bool positive = true;
    	if(x<0){
    		x=-x;
    		positive = false;
    	}
    	
    	long long int temp=0;
    	while(x>0){
    		temp = temp*10+x%10;
    		x/=10;
    	}
    	if((temp>>31)>0)
    		return 0;
    	
    	if(positive)
    	    return (int)temp;
    	return (int)-temp;
    }
    };

Log in to reply
 

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