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. BZOJ-3524 Couriers 可持久化线段树

    可持久化线段树,其实就是类主席树了.. 3524: [Poi2014]Couriers Time Limit: 20 Sec Memory Limit: 128 MB Submit: 1124 Sol ...

  2. 走进科学 WAF(Web Appllication Firewall)

    1. 前言 当WEB应用越来越为丰富的同时,WEB 服务器以其强大的计算能力.处理性能及蕴含的较高价值逐渐成为主要攻击目标.SQL注入.网页篡改.网页挂马等安全事件,频繁发生. 企业等用户一般采用防火 ...

  3. 查看apk包名package和入口activity名称的方法

    ctrl+r 打开CMD窗口 进入sdk-aapt目录 执行命令:aapt dump badging xx.apk 内容太多?不好看,没关系,全部拷出来,ctrl+f,so easy! package ...

  4. IDE 集成开发环境

    集成开发环境(IDE,Integrated Development Environment )是用于提供程序开发环境的应用程序,一般包括代码编辑器.编译器.调试器和图形用户界面工具.集成了代码编写功能 ...

  5. hdu 2041 超级楼梯

    斐波那契数列,看清题意,当前为第一阶,给出M(每次只能跨1阶或2阶) 从第一阶到M,若M=1,从1-1不用走,0种方法 若M=2 从1-2  一种方法  -> 1.走一次一阶 若M=3 从1-3 ...

  6. 将对象转为数组方法:延伸array_map函数在PHP类中调用内部方法

    public static function objectToArray($d) { if (is_object($d)) { $d = get_object_vars($d); } if (is_a ...

  7. JS 省,市,区

    // 纯JS省市区三级联动 // 2011-11-30 by http://www.cnblogs.com/zjfree var addressInit = function (_cmbProvinc ...

  8. 新浪微博客户端(8)-添加按钮到TabBar

    在tabBar的中部添加一个发送微博的按钮. DJTabBar.h #import <UIKit/UIKit.h> @class DJTabBar; @protocol DJTabBarD ...

  9. [Socket网络编程]一个封锁操作被对 WSACancelBlockingCall 的调用中断。

    原文地址:http://www.cnblogs.com/xiwang/archive/2012/10/25/2740114.html记录在此,方便查阅. C#中在使用UDPClient循环监听端口,在 ...

  10. POJ2823 Sliding Window (单调队列)

    POJ2823 Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 38342   Accepte ...