Compare numbers version1 and version1.
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
A bit comparison is good, the string into an integer, so you can ignore the impact of the predecessor 0.
1 classSolution {2 Public:3 intCompareversion (stringVersion1,stringVersion2) {4 intVal1, Val2;5 intIDX1 =0, idx2 =0;6 while(Idx1 < Version1.length () | | idx2 <version2.length ()) {7Val1 =0; 8 while(Idx1 <version1.length ()) {9 if(Version1[idx1] = ='.') {Ten++idx1; One Break; A } -Val1 = Val1 *Ten+ (Version1[idx1]-'0'); -++idx1; the } -Val2 =0; - while(Idx2 <version2.length ()) { - if(VERSION2[IDX2] = ='.') { +++idx2; - Break; + } AVal2 = Val2 *Ten+ (VERSION2[IDX2]-'0'); at++idx2; - } - if(Val1 > Val2)return 1; - if(Val1 < Val2)return-1; - } - return 0; in } -};
[Leetcode] Compare Version Numbers