Given two version numbers,&nbsp;version1 and version2, compare them.




Version numbers consist of one or more revisions joined by a dot&nbsp;'.'. Each revision&nbsp;consists of digits&nbsp;and may contain leading zeros. Every revision contains at least one character. Revisions are 0-indexed from left to right, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example&nbsp;2.5.33&nbsp;and&nbsp;0.1&nbsp;are valid version numbers.

To compare version numbers, compare their revisions in left-to-right order. Revisions are compared using their&nbsp;integer value ignoring any leading zeros. This means that revisions&nbsp;1&nbsp;and&nbsp;001&nbsp;are considered&nbsp;equal. If a version number does not specify a revision at an index, then&nbsp;treat the revision as&nbsp;0. For example, version&nbsp;1.0 is less than version&nbsp;1.1&nbsp;because their revision 0s are the same, but their revision 1s are&nbsp;0&nbsp;and&nbsp;1&nbsp;respectively, and&nbsp;0 &lt; 1.

Return the following:


	If version1 &lt; version2, return -1.
	If version1 &gt; version2, return 1.
	Otherwise, return 0.


&nbsp;
Example 1:

Input: version1 = "1.01", version2 = "1.001"
Output: 0
Explanation: Ignoring leading zeroes, both "01" and "001" represent the same integer "1".


Example 2:

Input: version1 = "1.0", version2 = "1.0.0"
Output: 0
Explanation: version1 does not specify revision 2, which means it is treated as "0".


Example 3:

Input: version1 = "0.1", version2 = "1.1"
Output: -1
Explanation: version1's revision 0 is "0", while version2's revision 0 is "1". 0 &lt; 1, so version1 &lt; version2.


&nbsp;
Constraints:


	1 &lt;= version1.length, version2.length &lt;= 500
	version1 and version2&nbsp;only contain digits and '.'.
	version1 and version2&nbsp;are valid version numbers.
	All the given revisions in&nbsp;version1 and version2&nbsp;can be stored in&nbsp;a&nbsp;32-bit integer.


class Solution:
    def compareVersion(self, v1: str, v2: str) -> int:
        v1, v2 = list(map(int, v1.split('.'))), list(map(int, v2.split('.')))  
        for rev1, rev2 in zip_longest(v1, v2, fillvalue=0):
            if rev1 == rev2:
                continue

            return -1 if rev1 < rev2 else 1 

        return 0
class Solution {
    public int compareVersion(String version1, String version2) {
	//Here we are going to Split the numbers by  . but since we cannot do that in java we will replace . with # and then do it 
        version1=version1.replace('.', '#');
        version2=version2.replace('.', '#');
        
        String v1[]=version1.split("#");
        String v2[]=version2.split("#");
        
        int i=0;
        
		
        while(i<v1.length || i<v2.length){
            //we will have inital value  0 as our array can out out index so taking that in considerration 
            Integer i1= 0;
            Integer i2= 0;
			//Here we are using removeing Zero function which will remove all the zeros before the string 
            if(i<v1.length){
                i1= Integer.valueOf(removezero(v1[i]));
            }
            if(i<v2.length){
                i2= Integer.valueOf(removezero(v2[i]));
            }
            //and the rest is just the comparison
            if(i1<i2){
                return -1;
            }
            else if(i1>i2){
                return 1;
            }
            i++;
        }
		//if all the statments are false then at last we can say that they are equal
        return 0;
    }
    String removezero(String s){
        String result ="";
        int i =0;
        while(i<s.length()){
            if(s.charAt(i)!='0'){
                result=s.substring(i, s.length());
                break;
            }
            i++;
        }
        return result!=""?result:"0";
    }
}
class Solution {
public:
    int compareVersion(string v1, string v2) {
        int ans = 0;
        int n1 = v1.size(), n2 = v2.size();
        
        for(int i=0,j=0; i<n1 || j<n2; ++i, ++j) {
            
            string s1 = "", s2 = "";

            while(i<n1 && v1[i] != '.') {
                if(s1.size() == 0 && v1[i] == '0') {
                    ++i; continue;
                }
                
                s1 += v1[i++];
            }
            
            while(j<n2 && v2[j] != '.') {
                if(s2.size() == 0 && v2[j] == '0') {
                    ++j; continue;
                }
                
                s2 += v2[j++];
            }
            
            if(s1.size() < s2.size()) return -1;
            else if(s2.size() < s1.size()) return 1;
            
            ans = s1.compare(s2);
            if(ans < 0) return -1;
            else if(ans > 0) return 1;
        }
        
        return 0;
        
    }
};
var compareVersion = function(version1, version2) {
    const v1 = version1.split('.')
    const v2 = version2.split('.')
	
	let max=Math.max(v1.length,v2.length);
    
    for(let i=0;i<max;i++){
        if(v1[i]&&v2[i]){ // if both v1 and v2 are present
            if(+v1[i] > +v2[i])return 1
            else if(+v1[i] < +v2[i])return -1
        }else if(v1[i] && +v1[i]!==0){ // if v1 is larger than v2 but make sure those digits are not 0.
            return 1
        }else if(v2[i] && +v2[i]!==0){ // if v2 is larger than v1 but make sure those digits are not 0.
            return -1
        }
    }
    return 0
};
Compare Version Numbers