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
解题思路:

先进行split,然后转为int比较即可,JAVA实现如下:

    static public int compareVersion(String version1, String version2) {
String[] s1=version1.split("\\.");
String[] s2=version2.split("\\.");
int[] num1=new int[Math.max(s1.length, s2.length)];
int[] num2=new int[Math.max(s1.length, s2.length)];
for(int i=0;i<s1.length;i++)
num1[i]= Integer.valueOf(s1[i]);
for(int i=0;i<s2.length;i++)
num2[i]= Integer.valueOf(s2[i]);
for(int i=0;i<num1.length;i++){
if(num1[i]>num2[i])
return 1;
else if(num1[i]<num2[i])
return -1;
}
return 0;
}

Java for LeetCode 165 Compare Version Numbers的更多相关文章

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

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

  2. Java [Leetcode 165]Compare Version Numbers

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

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

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

  4. Leetcode 165 Compare Version Numbers

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

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

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

  6. 165. Compare Version Numbers - LeetCode

    Question 165. Compare Version Numbers Solution 题目大意: 比较版本号大小 思路: 根据逗号将版本号字符串转成数组,再比较每个数的大小 Java实现: p ...

  7. 【刷题-LeetCode】165 Compare Version Numbers

    Compare Version Numbers Compare two version numbers version1 and version2. If *version1* > *versi ...

  8. 【一天一道LeetCode】#165. Compare Version Numbers

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...

  9. 【LeetCode】165 - Compare Version Numbers

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

随机推荐

  1. 【ZOJ 3870】 Team Formation

    题意 n个数,找出有几对a.b 符合 a ^ b > max(a,b) .^表示异或号 分析 对于数a,如果它的二进制是: 1 0 1  0 0 1,那么和它 ^ 后 能比他大的数就是: 0 1 ...

  2. BZOJ-2756 奇怪的游戏 黑白染色+最大流+当前弧优化+二分判断+分类讨论

    这个题的数据,太卡了,TLE了两晚上,各种调试优化,各种蛋疼. 2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MB Submit ...

  3. [转]基于overlayfs的硬盘资源隔离工具troot

    原文在这里:http://blog.donghao.org/tag/overlayfs/ 某些开发测试团队会有这样的需求:多个开发或测试人员在一台物理机上搭环境.装rpm包.测试等,目录很可能互相干扰 ...

  4. mybatis-spring从1.1升级到1.2所带来的dao层级的编写问题

    我们公司的项目使用spring+mybatis组合.所以就必须得使用mybatis-spring了.所以此处就昨日mybatis-spring从1.1升级到1.2所带来的dao层级的编写问题,做了一个 ...

  5. 异步http框架简介&实现原理

    1 )说明: Android开源代码:www.github.com 模拟一个异步http请求说明

  6. PHP中GD2的运用,注意编码格式的改变,以及head()函数之前不能有任何html元素包括空格!!!

    <?php header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式 header("Cont ...

  7. Jsonp简单认识(后端使用的是asp.net mvc)

    一.Jsonp简介:由于浏览器基于安全有同源策略(同源策略阻止从一个源加载的文档或脚本获取或设置另一个源加载的文档的属性)机制,所以前端无法使用Ajax来获取来获取其他域名下返回的数据,而Jsonp可 ...

  8. 基于.NET的大型Web站点StackOverflow架构分析(转)

    Stack Overflow网址:http://stackoverflow.com/ 当前访问量:每月9500PV(每天300多万PV) 当前Alexa排名:149 所用.NET技术:C#.Visua ...

  9. [Angularjs]asp.net mvc+angularjs+web api单页应用

    写在前面 最近的工作一直在弄一些h5的单页应用,然后嵌入到app的webview中.之前一直在用angularjs+html+ashx的一套东西.实在是玩腻了.然后就尝试通过asp.net mvc的方 ...

  10. ubuntu系统自带的火狐(firefox)如何安装Adobe Flash

    当你刚装完系统,发现打开某些网站时,提示你“需要安装flash”,然后你点击确定,过了一会,提示你安装失败. 我也是遇到这种情况.我第一个反应是,我先不用firefox,我安装chrome. 可是当你 ...