当前位置:网站首页>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
边栏推荐
- Data enhancement of semi supervised learning
- Digital currency: far-reaching innovation
- You probably haven't noticed the very important testing strategy in your work
- Turn -- bring it and use it: share a gadget for checking memory leaks
- Use of locust
- Turn -- use setjmp and longjmp in C language to realize exception capture and collaboration
- leetcode - 287. Find duplicates
- Detailed explanation of twenty common software testing methods (the most complete in History)
- 转--原来gdb的底层调试原理这么简单
- 毕业季,既是告别,也是新的开始
猜你喜欢
每日刷题记录 (十)
vSphere+、vSAN+来了!VMware 混合云聚焦:原生、快速迁移、混合负载
window安装wsl(二)
转--利用C语言中的setjmp和longjmp,来实现异常捕获和协程
tcpdump命令使用详解
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
毕业季,既是告别,也是新的开始
Congratulations on the release of friends' new book (send welfare)
shell 流程控制
Single step debugging analysis of rxjs observable of operator
随机推荐
Today's sleep quality record 71 points
Deadlock handling strategies - prevent deadlock, avoid deadlock, detect and remove deadlock
Force buckle 710 Random numbers in the blacklist
Pytorch's code for visualizing feature maps after training its own network
window10安装wsl(一)(WslRegisterDistribution ERROR)
Kubernetes create service access pod
力扣 710. 黑名单中的随机数
Two schemes of transforming the heat map of human posture estimation into coordinate points
vSphere+、vSAN+来了!VMware 混合云聚焦:原生、快速迁移、混合负载
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
[JUC learning road day 8] condition
Using emqx cloud to realize one machine one secret verification of IOT devices
工作中非常重要的测试策略,你大概没注意过吧
Daily question brushing record (10)
Favorite transaction code management tool in SAP GUI
Convergence and disposal suggestions of some Internet exposure surfaces
Cisco -- highly available and reliable network examination
常见的二十种软件测试方法详解(史上最全)
URL 介绍