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

自己写的代码跟discuss的最优代码几乎相同,不知道还有没有优化空间
int compareVersion(string version1, string version2) {
int i = , j = ;
while (i < version1.length() || j < version2.length())
{
int a1 = ;
int a2 = ;
while (i < version1.length() && version1[i] != '.')
a1 = a1 * + version1[i++] - '';
while (j < version2.length() && version2[j] != '.')
a2 = a2 * + version2[j++] - '';
i++; j++;
if (a1 > a2)
return ;
else if (a1 < a2)
return -;
}
return ;
}

Compare Version Numbers leetcode的更多相关文章

  1. 165. Compare Version Numbers - LeetCode

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

  2. 【leetcode 字符串处理】Compare Version Numbers

    [leetcode 字符串处理]Compare Version Numbers @author:wepon @blog:http://blog.csdn.net/u012162613 1.题目 Com ...

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

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

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

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

  5. 2016.5.21——Compare Version Numbers

    Compare Version Numbers 本题收获: 1.字符串型数字转化为整型数字的方法:s[i] - '0',( 将字母转化为数字是[i]-'A'   ) 2.srt.at(),substr ...

  6. [LeetCode] Compare Version Numbers 版本比较

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

  7. LeetCode Compare Version Numbers

    原题链接在这里:https://leetcode.com/problems/compare-version-numbers/ 用string.split()方法把原有string 从小数点拆成 str ...

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

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

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

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

随机推荐

  1. C# Unity游戏开发——Excel中的数据是如何到游戏中的 (三)

    本帖是延续的:C# Unity游戏开发——Excel中的数据是如何到游戏中的 (二) 前几天有点事情所以没有继续更新,今天我们接着说.上个帖子中我们看到已经把Excel数据生成了.bin的文件,不过其 ...

  2. HDU-1233-还是畅通工程(并查集)

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1233题目很简单(最小生成树) #include<cstdio> #include<io ...

  3. adb server无法启动方法,结束占用端口的进程

    adb server is out of date.  killing...ADB server didn't ACK* failed to start daemon *error: unknown ...

  4. IIS7和Tomcat7整合,即IIS7和Tomcat共用80端口

    IIS7和Tomcat7整合,即IIS7和Tomcat共用80端口 背景: 最近公司有一个项目要上线,需要用到iis和tomcat整合,共用80端口.由于公司的数据都非常重要,只通过端口映射到外网的8 ...

  5. JQuery hover toggle事件使用

    JQuery hover toggle事件使用: <%@ page language="java" import="java.util.*" pageEn ...

  6. Servlet中进行context属性的同步

    Servlet中进行context属性的同步: 必须所有使用context的servlet都进行synchronized才可以实现同步: servlet: package com.stono.serv ...

  7. Markdown使用教程

    Markdown 是一种 轻量级标记语言,主要特点是:使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML(或者HTML)文档". 本文参考了:语法手册.简书介绍. 常用语法 一.标 ...

  8. PariticalFilter在MFC上的运行,源代码公开

    由于项目需要,进行过一段时间的 PariticalFilter 研究.主要的工作就是将网络上的Console代码和Mfc融合在一起,并且添加了Mfc端的控制功能.       程序还有不完善的地方,现 ...

  9. C#在win10(win8)下读写记事本注意事项

    分析:由于windows10或者windows8系统机制问题,C#在读写txt文件的时候,可能会出现如下问题(对路径“”的访问被拒绝): 解决: 1.我们在C盘下面新建立一个记事本,会发下类似如下报错 ...

  10. LINQ查询表达式基础

    LINQ,语言集成查询(Language Integrated Query)是一组用C#和Visual Basic语言的扩展. 对于编写查询的开发人员来说,LINQ 最明显的"语言集成&qu ...