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.5is 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:
0.1 < 1.1 < 1.2 < 13.37
不用split("\\.") 的方法, 這題好惡心, 剛開始直接用字符串比較發(fā)現(xiàn)01 == 1?

后來變成數(shù)字比較, 發(fā)現(xiàn)1.0 == 1 ?所以短的還需要自動(dòng)補(bǔ)零;。。。。。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,917評(píng)論 0 23
  • 想寫點(diǎn)什么卻不知道怎么下手,不知道該如何用文字表達(dá),說到底還是讀書太少了。
    Amy就是me閱讀 184評(píng)論 1 0
  • 我八歲時(shí)就開始養(yǎng)了一只倉鼠當(dāng)我覺的自己有了一個(gè)伴陪我玩。我畫畫完它把我的畫給扯了,一定是我的畫難看何況老媽還這樣想...
    王小宸閱讀 282評(píng)論 0 1