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. node.js---sails项目开发(2)

    1.安装mongoDB,这里用brew安装 brew install mongodb 2. 启动数据库 mongod 3.再打开一个终端,连接数据库 mongo 4.启动成功后,接下来就是新建一个数据 ...

  2. laravel command命令行

    生成类 为了创建一个新命令,你可以使用Artisan中的 command:make 命令生成一个骨架作为你的起点: 生成一个命令类 php artisan command:make FooComman ...

  3. Linux基础——centos 跳过管理员密码进行登录(单用户模式、救援模式)

    这里列举了两种更改或者取消管理员密码登录Linux系统的方法,其实两种方法类似,都是想方设法跳过用户认定,直接更改用户文件.更改密码的过程. 为了跳过系统正常启动过程中的某些步骤,必须知道大致的系统启 ...

  4. PAT 天梯赛 L1-045. 宇宙无敌大招呼 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-045 AC代码 #include <iostream> #include <cstdio&g ...

  5. Kotlin学习记录3

    参考我的博客:http://www.isedwardtang.com/2017/09/04/kotlin-primer-3/

  6. IE6/7 下:inline-block解决方案

    6/IE7下:inline-block解决方案   IE6/IE7下对display:inline-block的支持性不好. 1.inline元素的display属性设置为inline-block时, ...

  7. winform webbrowser禁用网页target=blank

    /// <summary> /// 屏蔽target=_blank 的弹出窗口 /// </summary> /// <param name="sender&q ...

  8. tinyxml优化之一

    原文链接:http://www.cnblogs.com/zouzf/p/4154569.html 最近在搞XML解析优化,公司引擎用了tinyxml1和tinyxml2两个XML库,后者的效率比前者高 ...

  9. React之JSX语法

    1. JSX的介绍   JSX(JavaScript XML)——一种在React组件内部构建标签的类XML语法.react在不使用JSX的情况下一样可以工作,然而使用JSX可以提高组件的可读性,因此 ...

  10. 详细解读ARM寄存器之CPSR【转】

    本文转载自:https://blog.csdn.net/david_luyang/article/details/6276533 详细解读ARM寄存器之CPSR 整理人:卢阳 QQ:820927872 ...