当前位置:网站首页>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)
边栏推荐
- [Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
- 【RTKLIB 2.4.3 b34 】版本更新简介一
- Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
- Usage differences between isempty and isblank
- RTKLIB: demo5 b34f.1 vs b33
- [算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
- 2年经验总结,告诉你如何做好项目管理
- [算法] 劍指offer2 golang 面試題2:二進制加法
- Fundamentals of UD decomposition of KF UD decomposition [1]
- Error: symbol not found
猜你喜欢
Experience summary of autumn recruitment of state-owned enterprises
String类
rtklib单点定位spp使用抗差估计遇到的问题及解决
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
2022 National Games RE1 baby_ tree
Liste des boucles de l'interface graphique de défaillance
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
How do architects draw system architecture blueprints?
编辑距离(多源BFS)
Answer to "software testing" exercise: Chapter 1
随机推荐
图书管理系统小练习
堆排序【手写小根堆】
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache
染色法判定二分图
[GNSS] robust estimation (robust estimation) principle and program implementation
Employment of cashier [differential constraint]
Agile development helps me
wsl常用命令
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
KF UD分解之UD分解基础篇【1】
Fgui project packaging and Publishing & importing unity & the way to display the UI
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
Record: I accidentally wrote a recursion next time
[GNSS data processing] Helmert variance component estimation analysis and code implementation
Record: solution of 404 error of servlet accessing database in dynamic web project
isEmpty 和 isBlank 的用法区别
记录:Navicat Premium初次无法连接数据库MySQL之解决
Fundamentals of UD decomposition of KF UD decomposition [1]