Inconsistence between running testcase and OJ


  • 0
    A
    class Solution {
    public:
        int reverse(int x) {
        	stringstream ss;
        	ss << x;
        	string xx = ss.str();
        	if (xx[0] == '-'){
        	    string as(xx.size()-2, '0');
        		for (int i = 0; i < xx.size()-1; ++i){
        			as[i] = xx[xx.size()-1-i];
        		}
        		int r = (-1)*stol(as);
        		if (r< INT_MIN){
        			return 0;
        		} else {
        			return r;
        		}
        	}else {
        	    string as(xx.size()-1, '0');
        		for (int i = 0; i <xx.size(); ++i){
        			as[i] = xx[xx.size()-1-i];
        		}
        		int r = stol(as);
        		if (r > INT_MAX)
        			return 0;
        		else {
        			return r;
        		}
        	}
            
        }
    };

Log in to reply
 

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