当前位置:网站首页>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
边栏推荐
猜你喜欢
Chapter 7 of JVM series -- bytecode execution engine
ArrayList collection basic usage
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
8.2 文本预处理
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
1N5408-ASEMI整流二极管1N5408
Outsourcing for four years, abandoned
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
PCIe X1 插槽的主要用途是什么?
随机推荐
LeetCode149-直线上最多的点数-数学-哈希表
Epoll's et, lt working mode -- example program
Svn detailed use tutorial
Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
GIS数据处理-cesium中模型位置设置
1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2020,11,1),返回:星期日。 提示:
Explanation and example application of the principle of logistic regression in machine learning
【Proteus仿真】自动量程(范围<10V)切换数字电压表
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
eolink 如何助力遠程辦公
Matrix exchange row and column
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
go基础 反射
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
UML项目实例——抖音的UML图描述
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
三、梯度下降求解最小θ
A good tool: aardio
How do I open the win10 startup folder?
Detailed explanation of C language P2 selection branch statement