Different output between my pc and the judge

  • 1

    Here is my solution

    #include <iostream>
    #include <sstream>
    using namespace std;
    class Solution {
        int atoi(const char *str) {
            long value;
            stringstream ss;
            ss << str;
            ss >> value;
            if (value < INT_MIN || value > INT_MAX) {
                value = INT_MAX;
            return (int)value;
    int main(int argc, const char * argv[]) {
        cout << Solution().atoi("") << endl;
        return 0;

    on my pc, it output 0,
    but the oj output -1217490020.
    can someone tell me why ...
    thx :D

  • 0

    Stringstream might be redirecting str value to an integer with a different value from expected value

  • 0

    i think i found the reason. the parameter value need to be initialized to 0, the stringstream is ok. on my pc, long value, then the value = 0, but on oj, the value = -1217490020

Log in to reply

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