当前位置:网站首页>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
边栏推荐
- Unity_代码方式添加绑定按钮点击事件
- TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
- Comment eolink facilite le télétravail
- 中富金石财富班29800效果如何?与专业投资者同行让投资更简单
- Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
- 多语言通信基础 06 go实现grpc的四种数据流模式实现
- Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
- [detailed explanation of factory mode] factory method mode
- I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
- One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
猜你喜欢
LeetCode165-比较版本号-双指针-字符串
ArrayList collection basic usage
利用 MATLAB 编程实现最速下降法求解无约束最优化问题
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
qt之.pro文件详解
【JZ46 把数字翻译成字符串】
SVN详细使用教程
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
Brute force of DVWA low -- > High
随机推荐
epoll 的 ET,LT工作模式———实例程序
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
1 - first knowledge of go language
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
L'externalisation a duré quatre ans.
全连接层的作用是什么?
MySQL报错packet out of order
Introduction to Arduino for esp8266 serial port function
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
Model location setting in GIS data processing -cesium
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
抑郁症治疗的进展
想要成为架构师?夯实基础最重要
Is asemi ultrafast recovery diode interchangeable with Schottky diode
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
pnpm安装使用
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time
【JZ46 把数字翻译成字符串】