Easy to understand code using stod() C++


#1
int Solution::compareVersion(string A, string B) {
    bool firstdot = false;
    for( int i =0 ; i<A.length();i++ )
    {
        if(A[i]=='.'){
            if(!firstdot){
                firstdot=true;
            }else{
                A.erase(A.begin()+i);
            }
        }
    }
    firstdot = false;
    for( int i =0 ; i<B.length();i++ )
    {
        if(B[i]=='.'){
            if(!firstdot){
                firstdot=true;
            }else{
                B.erase(B.begin()+i);
            }
        }
    }
    long double bn = stod(B);
    long double an = stod(A);
    if(an>bn){return 1;}
    else if(an<bn){return -1;}
    else{return 0;}
}

#2

Fails for
1.13
1.1.3


#3

@Shahid_Nagra this fails for 1.2 and 1.13