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

注意可能会出现前置0的情况,所以分为小数点钱与小数点后转换成数字来判断,代码如下:

 class Solution {
public:
int compareVersion(string version1, string version2) {
int i1, i2;
int val1, val2;
for(i1 = , i2 = ; i1 < version1.size() || i2 < version2.size(); ++i1, ++i2){
val1 = ;
for(; i1 < version1.size(); ++i1){
if(version1[i1] == '.')
break;
val1 = val1 * + version1[i1] - '';
}
val2 = ;
for(; i2 < version2.size(); ++i2){
if(version2[i2] == '.')
break;
val2 = val2 * + version2[i2] - '';
}
if(val1 > val2)
return ;
else if(val1 < val2)
return -;
}
return ;
}
};

LeetCode OJ:Compare Version Numbers(比较版本字符串)的更多相关文章

  1. Leetcode OJ : Compare Version Numbers Python solution

    Total Accepted: 12400 Total Submissions: 83230     Compare two version numbers version1 and version2 ...

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

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

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

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

  4. leetcode:Compare Version Numbers

    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 vers ...

  6. 【leetcode】Compare Version Numbers(middle)

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

  7. Java for LeetCode 165 Compare Version Numbers

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

  8. Java [Leetcode 165]Compare Version Numbers

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

  9. Leetcode 165 Compare Version Numbers

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

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

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

随机推荐

  1. SQL CHECK sql server免费监控单实例工具

    SQL Check 阅读目录 SQL Check? 主要特点 说说不足 下载地址 小结 一款实时性能监测工具 回到目录 SQL Check? 一款实时监测SQL数据库性能.实时排查的问题的免费工具. ...

  2. codeigniter 中使用 phpexcel

    参考:Easily integrate/load PHPExcel into CodeIgniter Framework In order to get PHPExcel working with C ...

  3. mysql 关于join的总结

    本文地址:http://www.cnblogs.com/qiaoyihang/p/6401280.html mysql不支持Full join,不过可以通过UNION 关键字来合并 LEFT JOIN ...

  4. 单文件快速体验使用react输出hello_world

    看了下react官方的hello world教程, 感觉对新手很不友好.codepen虽然好用, 但是封装太多东西, 看起来 太抽象. 还是喜欢像学习jQuery那样, 直接在单文件中引入必要的js文 ...

  5. laravel queue队列使用

    一篇文章: laravel中的队列服务跟其他队列服务也没有什么不同,都是最符合人类思维的最简单最普遍的流程:有一个地方存放队列信息,一个PHP进程在运行时将任务写入,另外一个PHP守护进程轮询队列信息 ...

  6. beego——多种格式的数据输出

    beego当初设计的时候就考虑了API功能的设计,而我们在设计API的时候经常是输出JSON或者XML数据,那么beego提供了这样的方式直接输出: 1.JSON格式输出 func (this *Ad ...

  7. mysql binlog日志的三种模式

    1.statement level模式 每一条会修改数据的sql都会记录到master的bin-log中.slave在复制的时候sql进程会解析成和原来master端执行过的相同的sql来再次执行.优 ...

  8. Hbase1.2.4概述

    安装Hbase的时候,需要注意版本与Hadoop的版本兼容,具体查看:https://hbase.apache.org/book.html#basic.prerequisites 如下图: 我的Had ...

  9. Java并发之Semaphore的使用

    Java并发之Semaphore的使用 一.简介 今天突然发现,看着自己喜欢的球队发挥如此的棒,然后写着博客,这种感觉很爽.现在是半场时间,就趁着这个时间的空隙,说说Java并发包中另外一个重量级的类 ...

  10. 关于comparable接口

    参考博客: https://blog.csdn.net/nvd11/article/details/27393445 第一个例子 @Test public void fun1(){ List list ...