Most easy c++ solution using string conversion


#1

int Solution::compareVersion(string A, string B) {
long long int sa=A.size();
long long int sb=B.size();
long long int count=0;
long long int count1=0;
if(sa>sb)
{

 for(int i=0;i<sa;i++)
 
 {    if(A[i]=='.')
        count++;
     if(A[i]=='.'&&count>1)
     {
      //count++;
      A.erase(A.begin()+i);
     }
 }

}
else{

for(int i=0;i<sb;i++)
{
if(B[i]==’.’)
count1++;
if(B[i]==’.’&&count1>1)
{

      B.erase(B.begin()+i);
 }

}

}
double a=stold(A);
double b=stold(B);
if(a>b)
return 1;
else if(a<b)
return -1;
else if(a==b)
return 0;
}


#2

This solution is wrong and fails for the following:-

18.643.94
18.64.396

Expected Answer: 1

Answer with the code: -1

Weak test cases got you across