当前位置:网站首页>LeetCode165-比较版本号-双指针-字符串
LeetCode165-比较版本号-双指针-字符串
2022-04-23 14:48:00 【李烦烦搞快点】
Note:
把各个位置的数字抠出来比大小就好了,注意要全扣完,可能他俩前面的都相同,但是1的多出来个点,就是1更长了,那么说明1是大的
代码如下:
class Solution {
public:
int compareVersion(string version1, string version2) {
int i = 0, j = 0;
while(i < version1.size() || j < version2.size()){
string s1 = "0", s2 = "0";
while(i < version1.size() && version1[i] != '.')
s1 += version1[i ++];
while(j < version2.size() && version2[j] != '.')
s2 += version2[j ++];
int v1 = stoi(s1), v2 = stoi(s2);
if(v1 > v2) return 1;
else if(v1 < v2) return -1;
while(version1[i] == '.') i ++;
while(version2[j] == '.') j ++;
}
return 0;
}
};
版权声明
本文为[李烦烦搞快点]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Mr_Ghost812/article/details/124355173
边栏推荐
猜你喜欢
自动化的艺术
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
抑郁症治疗的进展
OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
Mds55-16-asemi rectifier module mds55-16
8.3 语言模型与数据集
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
随机推荐
全连接层的作用是什么?
UML项目实例——抖音的UML图描述
Parameter stack pressing problem of C language in structure parameter transmission
利用 MATLAB 编程实现最速下降法求解无约束最优化问题
Progress in the treatment of depression
[detailed explanation of factory mode] factory method mode
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
Matrix exchange row and column
冰冰学习笔记:一步一步带你实现顺序表
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
Want to be an architect? Tamping the foundation is the most important
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
8.3 语言模型与数据集
【无标题】
多语言通信基础 06 go实现grpc的四种数据流模式实现
Thread synchronization, life cycle
1N5408-ASEMI整流二极管1N5408
raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错