当前位置:网站首页>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
边栏推荐
- 轉載csdn文章操作
- 阿洛迷茫后的思考
- The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
- Kubernetes create service access pod
- shell 自定义函数
- 若干互联网暴露面的收敛及处置建议
- Favorite transaction code management tool in SAP GUI
- 数字化转型道阻且长,如何迈好关键的第一步
- Deadlock handling strategies - prevent deadlock, avoid deadlock, detect and remove deadlock
- 转--深入LUA脚本语言,让你彻底明白调试原理
猜你喜欢

Cut noodles C language

OpenVINO 模型性能评估工具—DL Workbench

今日睡眠质量记录71分
![[MySQL] index classification](/img/73/fb9f28457b373ad35d2f6068387b47.png)
[MySQL] index classification

Cisco test -- the concept and configuration test of routing

Ffmpeg learning notes

Explain JMM in detail

Fiori 应用通过 Adaptation Project 的增强方式分享

Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS

Cisco exam -- redundant network
随机推荐
Sogou wechat app reverse (II) so layer
正则系列之量词(Quantifiers)
Cisco exam -- redundant network
leetcode - 287. Find duplicates
Today's sleep quality record 71 points
104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
Copy ‘XXXX‘ to effectively final temp variable
Pytorch's code for visualizing feature maps after training its own network
Congratulations on the release of friends' new book (send welfare)
rviz打开后如何显示实时2D地图
工作中非常重要的测试策略,你大概没注意过吧
Appium automation test foundation - appium installation (I)
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
Flink SQL command line connection yarn
攻防演习防御体系构建之第三篇之建立实战化的安全体系
Advanced skills of testers: a guide to the application of unit test reports
Pytorch nn. functional. Simple understanding and usage of unfold()
cvpr2022 human pose estiamtion
Talk about what parameters ZABBIX monitors
激发新动能 多地发力数字经济