当前位置:网站首页>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)
边栏推荐
- 错误:排序与角标越界
- 十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
- [算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
- [algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
- Redis介绍与使用
- GPS高程拟合抗差中误差的求取代码实现
- 服务未正常关闭导致端口被占用
- Realization of the code for calculating the mean square error of GPS Height Fitting
- 继承和多态(上)
- 121 distributed interview questions and answers
猜你喜欢
[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
Heap sort [handwritten small root heap]
Detailed explanation of balanced binary tree is easy to understand
[算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和
阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
One article to get UDP and TCP high-frequency interview questions!
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
随机推荐
wsl常用命令
一文搞定 UDP 和 TCP 高频面试题!
2022 National Games RE1 baby_ tree
阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
[算法] 剑指offer2 golang 面试题10:和为k的子数组
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
Experience summary of autumn recruitment of state-owned enterprises
Employment of cashier [differential constraint]
GPS高程拟合抗差中误差的求取代码实现
How to reduce the shutdown time of InnoDB database?
第一人称视角的角色移动
Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
记录:Navicat Premium初次无法连接数据库MySQL之解决
MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景
Liste des boucles de l'interface graphique de défaillance
Dark chain lock (lca+ difference on tree)
Interview Essentials: talk about the various implementations of distributed locks!
使用rtknavi进行RT-PPP测试
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列