short c++


  • 0
    L

    int compareVersion(string& v1, string& v2) {
    istringstream is1(v1), is2(v2);
    for(string token1, token2; !is1.eof() || !is2.eof();){
    int n1 = is1.eof() ? 0 : (getline(is1, token1, '.'), stoi(token1)), n2 = is2.eof() ? 0 : (getline(is2, token2, '.'), stoi(token2));
    if(n1 > n2) return 1;
    else if(n1 < n2) return -1;
    }
    return 0;
    }


Log in to reply
 

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