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
The main purpose of this problem is to examine the comprehensiveness of the question, which embodies the performance advantage of C/C + +, and the Java code is posted.
Public classSolution { Public intcompareversion (String version1, String version2) {string[] sv1= Version1.split ("\ \.")); String[] Sv2= Version2.split ("\ \.")); intidx1 = 0; intIDX2 = 0; while(Idx1 < Sv1.length | | idx2 <sv2.length) { intV1 = 0; if(Idx1 <sv1.length) {V1=Integer.parseint (sv1[idx1]); Idx1++; } intV2 = 0; if(Idx2 <sv2.length) {v2=Integer.parseint (sv2[idx2]); IDX2++; } if(V1 <v2)return-1; if(V1 >v2)return1; } return0; }}
[Leetcode] Compare Version Numbers