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

Solution:类似于split的方法把字符串解析, 遇到'.'就判断之前的sum1和sum2

 class Solution {
public:
int compareVersion(string version1, string version2) {
int sum1=,sum2=;
int n1=version1.size(),n2=version2.size();
for(int i=,j=;i<n1||j<n2;i++,j++){
while(i<n1&&version1[i]!='.'){
sum1=sum1*+version1[i]-'';
i++;
}
while(j<n2&&version2[j]!='.'){
sum2=sum2*+version2[j]-'';
j++;
}
if(sum1>sum2)return ;
else if(sum1<sum2)return -;
else{
sum1=;
sum2=;
}
}
return ;
}
};

【LeetCode】165 - Compare Version Numbers的更多相关文章

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

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

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

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

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

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

  4. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...

  5. 165. Compare Version Numbers - LeetCode

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

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

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

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

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

  8. Java for LeetCode 165 Compare Version Numbers

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

  9. Java [Leetcode 165]Compare Version Numbers

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

随机推荐

  1. matlab 扩大虚拟内存

    今天服务器挂了..用了自己电脑结果爆内存,分享一个扩大虚拟内存的方法,经测试有效.. 使用Matlab生成很大的图片时,碰到了"out of memory"的错误,导致图片无法生成 ...

  2. 存根类STUB

    当我们创建一个指定各种方法集合的接口时,我们可以考虑使用"存根”STUB,“存根”就是用空方法体实现该接口中所有方法的类,这样我们就可以通过继承该“存根”创建一个实现该接口的类,这样一来,该 ...

  3. PHP Session可能会引起并发问题

    在进行Web应用程序开发的时候,人们经常会用Session存储数据.但可能有人不知道,在PHP中,Session使用不当可能会引起并发问题.印度医疗行业软件解决方案提供商Plus91 Technolo ...

  4. 蓝牙接收苹果手机通知 ANCS协议分析

    蓝牙接收苹果手机通知 ANCS协议分析 转载,请注明出处:http://www.cnblogs.com/alexcai/p/4321514.html 综述 现在有许多蓝牙手表.手环都能接收苹果ipho ...

  5. Python 中 os.path模板

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  6. 使用 httpkit 来替代 jetty

    Compojure 是一个基于 ring 的上层web开发框架.在 lein new compojure my-app 生成的项目中,默认是启用 jetty 服务器的,最近用到了 http-kit 中 ...

  7. Using dblink in Postgres

    select contractid from tcim_s_enterprice EXCEPT select contractid from dblink ( 'host=172.16.51.25 p ...

  8. Sublime Text 插件列表(整理中...)

    作为Java Web的开发者,前端和后端的技术都会用到,用了几款文本编辑器,Uedit32.EditPlus.Sublime Text等,发现还是Sublime Text用起来最方便. 首先安装pac ...

  9. .gitignore规则不生效的解决办法

    .gitignore规则不生效的解决办法 使用git 的时候,在.gitignore中已经添加了某个文件或者文件夹,但是使用git status还能看见该文件的修改提示--–说明.gitignore未 ...

  10. jquery radio 取值 取消选中 赋值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...