当前位置:网站首页>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
边栏推荐
猜你喜欢
全连接层的作用是什么?
外包干了四年,废了...
Bingbing learning notes: take you step by step to realize the sequence table
【工厂模式详解】工厂方法模式
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
MySQL报错packet out of order
外包幹了四年,廢了...
eolink 如何助力遠程辦公
The art of automation
你还不知道责任链模式的使用场景吗?
随机推荐
帧同步 实现
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
The art of automation
3、 Gradient descent solution θ
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
[NLP] HMM hidden Markov + Viterbi word segmentation
qt之.pro文件详解
Comment eolink facilite le télétravail
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
Bingbing learning notes: take you step by step to realize the sequence table
Contraction mapping theorem
外包干了四年,废了...
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
2-Go变量操作
Achievements in science and Technology (21)
MySQL报错packet out of order
1 - first knowledge of go language
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏