Compare numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return-1, otherwise ret Urn 0.
Assume that the version strings is non-empty and contain only digits and the .
character.
The .
character does not represent a, decimal point and was used to separate number sequences.
For instance, was not "both and 2.5
a half" or "half-to-version three", it is the fifth Second-level revision of the S Econd first-level revision.
Here are an example of version numbers ordering:
0.1 < 1.1 < 1.2 < 13.37
Note that there may be a pre-0 situation, so the decimal point is divided into a decimal point after the conversion into a number to determine the code as follows:
1 classSolution {2 Public:3 intCompareversion (stringVersion1,stringVersion2) {4 intI1, I2;5 intVal1, Val2;6 for(I1 =0, I2 =0; I1 < Version1.size () | | I2 < Version2.size (); ++I1, + +I2) {7Val1 =0;8 for(; I1 < Version1.size (); + +I1) {9 if(Version1[i1] = ='.')Ten Break; OneVal1 = Val1 *Ten+ VERSION1[I1]-'0'; A } -Val2 =0; - for(; i2 < Version2.size (); + +I2) { the if(Version2[i2] = ='.') - Break; -Val2 = Val2 *Ten+ Version2[i2]-'0'; - } + if(Val1 >val2) - return 1; + Else if(Val1 <val2) A return-1; at } - return 0; - } -};
Leetcode oj:compare version Numbers (compare versions string)