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. MySQL in不走索引

    优化前 SELECT*  FROM erp_helei mg WHERE mg.num = 602   AND mg.pid   IN   (10002559,10002561,10002562,10 ...

  2. swift 使用pod管理

    在oc 中使用pod 管理第三方库还是很方便的 今天来在swift中使用pod 来管理第三方库 其实还是很简单的 和oc 区别不大  下面来说说我遇到的一些问题及解决方法 当然使用pod 你要先安装p ...

  3. C#中IDisposable

    在Net中,由GC垃圾回收线程掌握对象资源的释放,程序员无法掌控析构函数的调用时机.对于一些非托管资源,比如数据库链接对象等,需要实现IDisposable接口进行手动的垃圾回收.那么什么时候使用Id ...

  4. 百度人脸识别api及face++人脸识别api测试(python)

    一.百度人脸识别服务 1.官方网址:http://apistore.baidu.com/apiworks/servicedetail/464.html 2.提供的接口包括: 2.1 多人脸比对:请求多 ...

  5. Linux编程之PING的实现

    PING(Packet InterNet Groper)中文名为因特网包探索器,是用来查看网络上另一个主机系统的网络连接是否正常的一个工具.ping命令的工作原理是:向网络上的另一个主机系统发送ICM ...

  6. Redis key 相关命令

    其实本质上,Redis 就是一个Key---Value 数据库.这里我先介绍下Redis中关于的key的相关命令, 注意:key是字符串存储,但是不能使用 空格 或者 “\n”,value 则可以使用 ...

  7. linux 中c/c++实现终端命令行命令

    在终端中可以从用下面命令获得帮助: man system 在c/c++代码中实现和在终端中输入的命令行一样的效果,以命令(audacious -p &)为例,该代码实现用audacious在后 ...

  8. .net 网站应对压力的一些方案总结

    开年比较空,抽时间写个博文,总结下自己工作里的一些应对网站访问压力的技术方案. 自己项目现在大概一天50W的pv.已从前端到后端的顺序总结下自己用的一些方案. 一. 前端页面: 1.首先减少资源的大小 ...

  9. ajax问题

    1. 代码:var i;for(i=0;i<10;i++){      ajaxServise(i);} 在for循环中调用ajax方法  补充页面上的数据,这样写是错误的,他不会每执行一次fo ...

  10. 关于bootstrap 在MVC里 模态框里加载iframe页面做编辑的时候

    前台代码 <div class="modal fade" id="myModal" tabindex="-1" role=" ...