当前位置:网站首页>Leetcode165 compare version number double pointer string
Leetcode165 compare version number double pointer string
2022-04-23 14:49:00 【Li Fan, hurry up】
Note:
Just pick out the numbers of each position and compare them with the size , Pay attention to fully buckle , Maybe both of them are the same in front , however 1 More points , Namely 1 Longer , It means that 1 It's big
The code is as follows :
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;
}
};
版权声明
本文为[Li Fan, hurry up]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231447599623.html
边栏推荐
- qt之.pro文件详解
- When splicing HQL, the new field does not appear in the construction method
- Master in minutes --- ternary operator (ternary operator)
- [stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
- Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time
- 拼接hql时,新增字段没有出现在构造方法中
- LeetCode 练习——396. 旋转函数
- Realization of four data flow modes of grpc based on Multilingual Communication
- L'externalisation a duré quatre ans.
- 在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
猜你喜欢
MDS55-16-ASEMI整流模块MDS55-16
LeetCode149-直线上最多的点数-数学-哈希表
LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
详解TCP的三次握手
GIS数据处理-cesium中模型位置设置
Find daffodils - for loop practice
[servlet] detailed explanation of servlet (use + principle)
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
随机推荐
2-GO variable operation
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
Frame synchronization implementation
想要成为架构师?夯实基础最重要
【无标题】
we引用My97DatePicker 实现时间插件使用
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
[proteus simulation] automatic range (range < 10V) switching digital voltmeter
Alexnet model
Don't you know the usage scenario of the responsibility chain model?
UML项目实例——抖音的UML图描述
Detailed explanation of C language P2 selection branch statement
epoll 的 ET,LT工作模式———实例程序
一款不错的工具:aardio
go基础 反射
Progress in the treatment of depression
qt之.pro文件详解
Brute force of DVWA low -- > High
thinkphp5+数据大屏展示效果