当前位置:网站首页>165. Compare version number - string
165. Compare version number - string
2022-07-06 13:05:00 【The_ Dan】
class Solution {
public:
int compareVersion(string version1, string version2) {
int vtoi1 = 0, vtoi2 = 0; // convert to int Compare
int m = version1.size(), n = version2.size();
int i = 0, j = 0;
while(i < m || j < n){
int temp1 = 0, temp2 = 0; // Store the value of this segment
while(i < m && version1[i] != '.'){
temp1 = temp1 * 10 + version1[i] - '0';
i++;
}
i++;
while(j < n && version2[j] != '.'){
temp2 = temp2 * 10 + version2[j] - '0';
j++;
}
j++;
vtoi1 += temp1;
vtoi2 += temp2;
if(vtoi1 > vtoi2)
return 1;
else if(vtoi1 < vtoi2)
return -1;
}
return 0;
}
};
Accepted
81/81 cases passed (0 ms)
Your runtime beats 100 % of cpp submissions
Your memory usage beats 80.23 % of cpp submissions (6 MB)
边栏推荐
- Detailed explanation of balanced binary tree is easy to understand
- C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
- Fairygui bar subfamily (scroll bar, slider, progress bar)
- On March 15, the official version of go 1.18 was released to learn about the latest features and usage
- 2-year experience summary, tell you how to do a good job in project management
- 10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache
- String类
- [rtklib 2.4.3 B34] version update introduction I
- Problems and solutions of robust estimation in rtklib single point location spp
- [algorithm] sword finger offer2 golang interview question 5: maximum product of word length
猜你喜欢
FairyGUI条子家族(滚动条,滑动条,进度条)
[Chongqing Guangdong education] Shandong University College Physics reference materials
Detailed explanation of balanced binary tree is easy to understand
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
FairyGUI循環列錶
《软件测试》习题答案:第一章
随机推荐
使用rtknavi进行RT-PPP测试
服务未正常关闭导致端口被占用
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
Problems and solutions of robust estimation in rtklib single point location spp
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
How to reduce the shutdown time of InnoDB database?
FGUI工程打包发布&导入Unity&将UI显示出来的方式
[算法] 剑指offer2 golang 面试题1:整数除法
错误:排序与角标越界
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
【干货】提升RTK模糊度固定率的建议之周跳探测
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
Record: solution of 404 error of servlet accessing database in dynamic web project
[algorithm] sword finger offer2 golang interview question 5: maximum product of word length
Music playback (toggle & playerprefs)
继承和多态(下)
Record: I accidentally wrote a recursion next time
10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache
Fgui project packaging and Publishing & importing unity & the way to display the UI