当前位置:网站首页>Compare the version number [double pointer to intercept the string you want]
Compare the version number [double pointer to intercept the string you want]
2022-07-01 23:03:00 【REN_ Linsen】
Double pointer
Preface
determine begin/end, It determines a string , Use double pointers to intercept qualified strings . Of course, double pointers do more than that .
One 、 Compare version number

Two 、 Double pointer
package everyday.doublePoint;
// Compare version number
public class CompareVersion {
/* target: Compare version1 and version2, Greater than return 1, Less than return -1, Equal return 0. The comparison of the two is different from the ordinary string comparison , You need to remove the leading 0. */
public int compareVersion(String version1, String version2) {
int i1 = 0, i2 = 0;
int j1 = i1, j2 = i2;
while (j1 < version1.length() || j2 < version2.length()) {
// Remove the leading as 0.
while (i1 < version1.length() && version1.charAt(i1) == 0) ++i1;
// Count
while (++j1 < version1.length() && version1.charAt(j1) != '.') ;
// If there is no version number in the subsequent sequence, it will be regarded as 0
String s1 = i1 >= version1.length() ? "" : version1.substring(i1, j1);
int val1 = s1 == "" ? 0 : Integer.parseInt(s1);
// to update i1/j1
i1 = ++j1;// Walk past ellipsis .
// Empathy ,i2/j2 such .
while (i2 < version2.length() && version2.charAt(i2) == 0) ++i2;
while (++j2 < version2.length() && version2.charAt(j2) != '.') ;
String s2 = i2 >= version2.length() ? "" : version2.substring(i2, j2);
int val2 = s2 == "" ? 0 : Integer.parseInt(s2);
// to update i2/j2
i2 = ++j2;// Walk past ellipsis .
// Start comparing
if (val1 > val2) return 1;
if (val1 < val2) return -1;
}
return 0;
}
}
summary
1) Double pointer .
reference
边栏推荐
- 工作中非常重要的测试策略,你大概没注意过吧
- MySQL -- index of InnoDB storage engine
- Favorite transaction code management tool in SAP GUI
- 使用3DMax制作一个象棋棋子
- [target tracking] | single target tracking indicator
- window安装wsl(二)
- Turn -- use setjmp and longjmp in C language to realize exception capture and collaboration
- Flink SQL command line connection yarn
- 想请教一下,证券开户选择哪个证券比较好?手机开户是安全么?
- 正则系列之组和范围(Groups and Ranges)
猜你喜欢

转--原来gdb的底层调试原理这么简单

tcpdump命令使用详解

【Kotlin 第三方 】coil koltin协程图片加载库Coil类似Glide的图片加载第三方

Réimpression de l'article csdn

MySQL -- index of MyISAM storage engine

window安装wsl(二)

Rust language - Introduction to Xiaobai 05

测试人进阶技能:单元测试报告应用指南

91. (cesium chapter) cesium rocket launch simulation

Quantifiers of regular series
随机推荐
每日刷题记录 (十)
Réimpression de l'article csdn
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
OpenVINO 模型性能评估工具—DL Workbench
el-input文本域字数限制,超过显示变红并禁止输入
Use and function of spark analyze command map join broadcast join
Cisco test -- the concept and configuration test of routing
The principle, testing and Countermeasures of malicious software reverse closing EDR
Arlo's thinking after confusion
Cisco -- highly available and reliable network examination
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 release | geek headlines
Friendly serial assistant tutorial_ How to configure friendly serial port debugging assistant - tutorial on using friendly serial port debugging assistant
447 Bili Bili noodles warp 1
想请教一下,证券开户选择哪个证券比较好?手机开户是安全么?
Vsphere+ and vsan+ are coming! VMware hybrid cloud focus: native, fast migration, mixed load
Electron学习(三)之简单交互操作
今日睡眠质量记录71分
数字货币:影响深远的创新
cvpr2022 human pose estiamtion
map容器