当前位置:网站首页>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
边栏推荐
- 常见的二十种软件测试方法详解(史上最全)
- [kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party
- 【嵌入式系统课设】单个按键控制LED灯
- 毕业季,既是告别,也是新的开始
- ECMAScript 2022 was officially released. Have you heard about it?
- 正则系列之量词(Quantifiers)
- 死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
- 激发新动能 多地发力数字经济
- [literacy] deep / shallow, local / global features in machine learning image processing
- Explain JMM in detail
猜你喜欢

104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目

Advanced skills of testers: a guide to the application of unit test reports

I graduated from college in 14 years and changed to software testing in 3 months. My monthly salary was 13.5k. At the age of 32, I finally found the right direction

Cisco -- an external tool for WAN's concept examination

14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向

Tcpdump command usage details

MySQL -- index of InnoDB storage engine

447 Bili Bili noodles warp 1

数字货币:影响深远的创新

rviz打开后如何显示实时2D地图
随机推荐
Arlo's thinking after confusion
plain framework的实际应用和扩展
Explain JMM in detail
正则系列之量词(Quantifiers)
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine
A few minutes before work, I found out V-model and The difference between sync
Rank ranking with MySQL 5.7
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
Using securecrtportable to remotely connect virtual machines
转--拿来即用:分享一个检查内存泄漏的小工具
Origin2018 installation tutorial "recommended collection"
El input text field word limit, beyond which the display turns red and input is prohibited
Preparation of functional test report
rviz打开后如何显示实时2D地图
毕业季,既是告别,也是新的开始
工作中非常重要的测试策略,你大概没注意过吧
若干互联网暴露面的收敛及处置建议
[JUC learning road day 9] barrier derivatives
Contents of other parts of the map