165 Compare Version Numbers
Compare two version numbersversion1andversion2. Ifversion1>version2return 1, ifversion1<version2return -1, otherwise return 0.
You may assume that the version strings are non-empty and contain only digits and the.
character.
The.
character does not represent a decimal point and is used to separate number sequences.
For instance,2.5
is not "two and a half" or "half way to version three", it is the fifth second-level revision of the second first-level revision.
Here is an example of version numbers ordering:
虽然这题貌似简单,可以是也有需要注意的地方。首先split函数里,"."是得escape的,不然切不开。另外,输入虽然只包含数字和点,但别天真的以为数字一定合法。测试用例里有01,00这样的输入,所以比较的时候不能直接比较字符串要换成数字再比较。
Last updated