Question:
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
1. Classification of types of questions:
2, Ideas:
3. Complexity of Time:
4. Code:
Public classSolution { Public intcompareversion (String version1, String version2) {string[] v1=version1.split ("\ \")); String[] V2=version2.split ("\ \")); intx=Math.max (V1.length, v2.length); int[] i1=Convertstringarraytointegerarray (v1,x); int[] i2=Convertstringarraytointegerarray (v2,x); for(inti=0;i<x;i++) { if(i1[i]>I2[i])return1; Else if(i1[i]<I2[i])return-1; } return0; } Public int[] Convertstringarraytointegerarray (string[] str,intl) {intlen=str.length; int[] r=New int[L]; for(inti=0;i<len;i++) {R[i]=Integer.parseint (Str[i]); } returnR; }}
5. Optimization:
6. Extension:
[Leetcode] Compare Version Numbers