Total Accepted: 12400 submissions: 83230
Compare numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return-1, otherwise R Eturn 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 Second First-level revision.
Here are an example of version numbers ordering:
0.1 < 1.1 < 1.2 < 13.37
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
Solution:
1 classSolution:2 #@param version1, a string3 #@param version2, a string4 #@return An integer5 defcompareversion (self, Version1, Version2):6splited1, Splited2 = Version1.split ('.'), Version2.split ('.')7diff = Len (splited1)-Len (splited2)8 9ext = splited1ifDiff < 0ElseSplited2;TenExt.extend (['0' forIinchRange (ABS (diff))) One A forA, binchZip (splited1, splited2): -RET =cmp (int (a), int (b)) - ifRet! =0: the returnret - return0
Leetcode oj:compare Version Numbers Python Solution