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

注意:版本格式可能会有多个子版本

class Solution {
public:
int compareVersion(string version1, string version2) {
vector<int> arr_v1,arr_v2;
int pos1_pre = , pos2_pre = , pos1=version1.find_first_of('.'),pos2=version2.find_first_of('.');
while(pos1!=-){
arr_v1.push_back(atoi(version1.substr(pos1_pre,pos1).c_str()));
pos1_pre = pos1+;
pos1 = version1.find_first_of('.',pos1_pre);
}
arr_v1.push_back(atoi(version1.substr(pos1_pre).c_str())); while(pos2!=-){
arr_v2.push_back(atoi(version2.substr(pos2_pre,pos2).c_str()));
pos2_pre = pos2+;
pos2 = version2.find_first_of('.',pos2_pre);
}
arr_v2.push_back(atoi(version2.substr(pos2_pre).c_str())); int size1 = arr_v1.size();
int size2 = arr_v2.size();
int size = min(size1,size2);
for(int i = ; i < size; i++){
if(arr_v1[i] > arr_v2[i]) return ;
else if(arr_v1[i] < arr_v2[i]) return -;
}
if(size == size1){
for(int i = size; i < size2; i++){
if(arr_v2[i]!=) return -;
}
return ;
}
else{
for(int i = size; i < size1; i++){
if(arr_v1[i]!=) return ;
}
return ;
}
}
};

165. Compare Version Numbers (String)的更多相关文章

  1. 165. Compare Version Numbers - LeetCode

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

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

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

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

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

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

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

  5. Java for LeetCode 165 Compare Version Numbers

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

  6. 【LeetCode】165 - Compare Version Numbers

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

  7. Java [Leetcode 165]Compare Version Numbers

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

  8. 165. Compare Version Numbers

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

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

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

随机推荐

  1. [转]講講 John Carmack 的快速反平方根演算法

    講講 John Carmack 的快速反平方根演算法  原地址http://213style.blogspot.com/2014/07/john-carmack.html 本篇的主題很簡單,講講怎麼快 ...

  2. oracle基础 管理索引

    转自:https://blog.csdn.net/without_bont/article/details/79862112 管理索引   ---    原理介绍 索引是用于加速数据存取的数据对象.合 ...

  3. Django 模板格式化日期

    在模板中格式化日期: {{ post.date|date:”Y-m-d H:i:s” }}

  4. axios请求带上cookie配置

    Axios.defaults.withCredentials = true 参考:https://segmentfault.com/a/1190000008872646

  5. day40-socket编程

    一.socket介绍 看socket之前,先来回顾一下五层通讯流程: 但实际上从传输层开始以及以下,都是操作系统帮咱们完成的 Socket又称为套接字,它是应用层与TCP/IP协议族通信的中间软件抽象 ...

  6. day07-while,for循环

    1.循环语句 Python提供了for循环和while循环while在给定的判断条件为 true 时执行循环体,否则退出循环体.for重复执行语句嵌套循环可以在while循环体中嵌套for.while ...

  7. flash builder 4.7 打开闪退解决办法

    删除文件 /Users/apple/Documents/Adobe Flash Builder 4.7/.metadata/.plugins/org.eclipse.ui.workbench/work ...

  8. window 服务

    c#写windows服务   序言 前段时间做一个数据迁移项目,刚开始用B/S架构做的项目,但B/S要寄存在IIs中,而IIs又不稳定因素,如果重启IIs就要打开页面才能运行项目.有不便之处,就改用W ...

  9. 【360】pandas.DataFrame、array、list 之间转换

    pandas.DataFrame → array → list values 可以转成 array array.tolist() 可以转成 list >>> c 0 1 2 0 0 ...

  10. Linux ftp软件安装、配置和启动

    ftp软件安装.配置和启动及相关问题的解决在测试环境使用过程中经常使用.本文以SuSE11sp1上vsftpd的安装过程进行介绍. 测试环境 SuSE11sp1 vsftp软件安装检查 1.rpm - ...