Easy Solution O(n) time


#1

vector < double> fnn(string version, int len){
vector < double > ans(len,0);
int j=0;
for(int i=0;i<version.size();i++){
if(version[i]==’.’){
j++;
continue;
}
ans[j]=(ans[j]*10)+(version[i]-‘0’);
}
return ans;
}
int Solution::compareVersion(string A, string B) {
int len =max(A.size(),B.size());
vector< double> a,b;
a=fnn(A,len);
b=fnn(B,len);
for(int i=0;i<len;i++){
// cout<<a[i]<<" "<<b[i]<<endl;
if(a[i]>b[i]) return 1;
else if(a[i]<b[i]) return -1;
}
return 0;
}