c++ clean 0ms


  • 0
    F
    class Solution {
    public:
        int compareVersion(string version1, string version2) {
            int n1=count(version1.begin(),version1.end(),'.');
            int n2=count(version2.begin(),version2.end(),'.');
            
            while(n1<n2)
            {
                version1+=".0";
                n1++;
            }
            
            while(n2<n1)
            {
                version2+=".0";
                n2++;
            }
                    
            stringstream ss1(version1);
            stringstream ss2(version2);
            string v1,v2;
            while(getline(ss1,v1,'.') && getline(ss2,v2,'.'))
            {
                if(stoi(v1)>stoi(v2))
                    return 1;
                else if(stoi(v1)<stoi(v2))
                    return -1;
            }
            return 0;
    
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.