Total Accepted: 12400 Total Submissions: 83230

 
 

Compare two version numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return -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:

0.1 < 1.1 < 1.2 < 13.37

Credits:
Special thanks to @ts for adding this problem and creating all test cases.

Solution:

 class Solution:
# @param version1, a string
# @param version2, a string
# @return an integer
def compareVersion(self, version1, version2):
splited1, splited2 = version1.split('.'), version2.split('.')
diff = len(splited1) - len(splited2) ext = splited1 if diff < 0 else splited2;
ext.extend(['' for i in range(abs(diff))]) for a, b in zip(splited1, splited2):
ret = cmp(int(a), int(b))
if ret != 0:
return ret
return 0

Leetcode OJ : Compare Version Numbers Python solution的更多相关文章

  1. [LeetCode] 165. Compare Version Numbers 比较版本数

    Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...

  2. 【leetcode】Compare Version Numbers

    题目描述: Compare two version numbers version1 and version2. If version1 > version2 return 1, if vers ...

  3. 【leetcode】Compare Version Numbers(middle)

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  4. ✡ leetcode 165. Compare Version Numbers 比较两个字符串数字的大小 --------- java

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  5. leetcode:Compare Version Numbers

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  6. Java [Leetcode 165]Compare Version Numbers

    题目描述: Compare two version numbers version1 and version2.If version1 > version2 return 1, if versi ...

  7. Java for LeetCode 165 Compare Version Numbers

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  8. Leetcode 165 Compare Version Numbers

    题意:比较版本号的大小 有点变态,容易犯错 本质是字符串的比较,请注意他的版本号的小数点不知1个,有的会出现01.0.01这样的变态版本号 class Solution { public: int c ...

  9. 【LeetCode】165. Compare Version Numbers 解题报告(Python)

    [LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

随机推荐

  1. php站点

    thinkphp wordpress 记事狗 phpcms http://jingyan.baidu.com/article/4b07be3c61e93e48b380f3fd.html

  2. jsp 获取表单值, 提交类型为multipart/form-data处理

    //tt.jsp<script type="text/javascript"> function doSubmit(){ alert("aaaaaa" ...

  3. Eclipse 插件开发 —— 深入理解查找(Search)功能及其扩展点

    引言 查找功能是计算机语言开发环境 / 平台的一个非常重要的特性.Eclipse 也不例外,它提供了丰富的查找功能(用户可以输入正则表达式或任意字符串,指定查找范围和匹配选项等等),并且提供了简单易用 ...

  4. Visual C++ 6.0静态、动态链接库

    1.什么是静态连接库,什么是动态链接库          静态链接库与动态链接库都是共享代码的方式,如果采用静态链接库,则无论你愿不愿意,lib 中的指令都全部被直接包含在最终生成的 EXE 文件中了 ...

  5. HDU 1203 I NEED A OFFER!(01 背包DP)

    点我看题目 题意 : 中文题不详述. 思路 :类似于01背包的DP,就是放与不放的问题,不过这个要求概率,至少得到一份offer的反面就是一份也得不到,所以先求一份也得不到的概率,用1减掉就可以得到所 ...

  6. POJ 3792 Area of Polycubes(思维)

    点我看题目 题意 : 其实我也说不太清楚题意,就是给你很多方块,每放一块方块,都要和前一块有一个面相接,如果不相接,就输出NO,并输出是第几个方块不相接的.如果满足每一个都和前边相接,那就判断所有没有 ...

  7. Android 进程保活招式大全

    目前市面上的应用,貌似除了微信和手Q都会比较担心被用户或者系统(厂商)杀死问题.本文对 Android 进程拉活进行一个总结. Android 进程拉活包括两个层面: A. 提供进程优先级,降低进程被 ...

  8. P125、面试题19:二叉树的镜像

    题目:请完成一个函数,输入一个二叉树,该函数输出它的镜像二叉树结点的定义如下:struct BinaryTreeNode{       int     m_nValue;       BinaryTr ...

  9. R语言学习笔记:因子(Factors)

    因子提供了一个简单并且紧凑的形式来处理分类(名义上的)数据.因子用”水平level”来表示所有可能的取值.如果数据集有取值个数固定的名字变量,因子就特别有用. > g<-c("f ...

  10. win7打开或关闭windows功能 提示“出现错误,并非所有的功能被更改”,管理员权限惹的祸

    2013-07-25 18:12:06 最近要用到windows的telnet功能,本来是很简单的事情,因为管理员权限的问题,花了不少时间,才发现是管理员权限惹的祸,更滑稽的是,自己一直以来都不是管理 ...