# Easiest and understandable solution in O(n)

#1

Make two vectors and insert integers before ‘.’ and then compare each one to get the output.
int Solution::compareVersion(string A, string B) {

``````long double l1=A.length();
long double l2=B.length();
vector<long double> v1,v2;
string str1="";
long double sum1=0;
for(long double i=0;i<l1;i++)
{
if(A[i]=='.')
{
sum1=stold(str1);
v1.push_back(sum1);
str1="";
}
else
{
str1+=A[i];
}
}
v1.push_back(stold(str1));
string str2="";
long double sum2=0;
for(long double i=0;i<l2;i++)
{

if(B[i]=='.')
{
sum2=stold(str2);
v2.push_back(sum2);
str2="";
}
else
{
str2+=B[i];
}
}
v2.push_back(stold(str2));
long double s1=v1.size();
long double s2=v2.size();

if(s1>=s2)
{
for(long double i=0;i<s1;i++)
{
if(i==s2&&v1[i]!=0)
return 1;
else if(v1[i]>v2[i])
{
return 1;
}
else if(v1[i]<v2[i])
{
return -1;
}

}
}
else
{
for(long double i=0;i<s2;i++)
{
if(i==s1&&v2[i]!=0)
return -1;
else if(v1[i]>v2[i])
{
return 1;
}
else if(v1[i]<v2[i])
{
return -1;
}

}

}

return 0;
}``````

#2

bro why stoi, atol, and atoll not working???

#3

Bro, some times the string may be too large to be converted to a number. Cases are large.