My code is right through running, why I get the WA after I submitted?


  • 0
    F

    My code is right through running, why I get the WA after I submitted?

    class Solution {

    public:

    int compareVersion(string version1, string version2) {
        if(version1.compare(version2) == 0) return 0;
            int i = 0,j = 0,k = 1;
            int num1 = 0,num2 = 0;
            
            for(int n = 0; n < 2; n++){            
    
                while(version1[i] == '0') i++;
                while(version2[j] == '0') j++;
                
                while(version1[i] != '.' && version1[i] != 0) 
                {num1 = num1 * 10 + (version1[i] - '0'); i++;}
                while(version2[j] != '.' && version2[j] != 0) 
                {num2 = num2 * 10 + (version2[j] - '0'); j++;}
                i++;
                j++;
    
                if(num1 > num2) return 1;
                else if(num1 < num2) return -1;
                num1 = 0;num2 = 0;
            }
            return 0;
        
    }
    

    };


Log in to reply
 

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