C++ Solution... will work for large numbers


#1
int myCompare(string num_a, string num_b){
    int i=0;
    int j=0;
    while(num_a[i]=='0') i++;
    while(num_b[j]=='0') j++;
    if(num_a.size()-i > num_b.size()-j) return 1;
    if(num_a.size()-i < num_b.size()-j) return -1;
    while(i<num_a.size()){
        int t=num_a[i]-num_b[j];
        if(t>0) return 1;
        if(t<0) return -1;
        i++; j++;
    }
    return 0;
}

int Solution::compareVersion(string A, string B){
    int i=0;
    int j=0;
    while(i<A.size() || j<B.size()){
        string num_a;
        while(i<A.size() && A[i]!='.'){
            num_a.push_back(A[i]);
            i++;
        }
        i++;
        string num_b;
        while(j<B.size() && B[j]!='.'){
            num_b.push_back(B[j]);
            j++;
        }
        j++;
        if(myCompare(num_a, num_b) != 0) return myCompare(num_a, num_b); 
    }
    return 0;
}