当前位置:网站首页>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
边栏推荐
- A blog allows you to learn how to write markdown on vscode
- do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
- 科技的成就(二十一)
- raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
- 1 - first knowledge of go language
- go基础 反射
- SQL中HAVING和WHERE的区别
- I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
- AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
- 1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
猜你喜欢
全连接层的作用是什么?
We reference My97DatePicker to realize the use of time plug-in
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
你还不知道责任链模式的使用场景吗?
thinkphp5+数据大屏展示效果
Chapter 7 of JVM series -- bytecode execution engine
Outsourcing for four years, abandoned
【无标题】
随机推荐
Contraction mapping theorem
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
1n5408-asemi rectifier diode
编程哲学——自动加载、依赖注入与控制反转
UML项目实例——抖音的UML图描述
Model location setting in GIS data processing -cesium
1N5408-ASEMI整流二极管1N5408
QT interface optimization: double click effect
eolink 如何助力遠程辦公
ASEMI整流模块MDQ100-16在智能开关电源中的作用
QT interface optimization: QT border removal and form rounding
你還不知道責任鏈模式的使用場景嗎?
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
压缩映射定理
epoll 的 ET,LT工作模式———实例程序
UML project example -- UML diagram description of tiktok
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc