class Solution {
public int compareVersion(String version1, String version2) {
int i = 0, j = 0;
int len1 = version1.length(), len2 = version2.length();
while(i < len1 || j < len2){
int a = 0, b = 0;
// *10为了去除10
while(i < len1 && version1.charAt(i) != '.'){
a = a * 10 + version1.charAt(i) - '0';
++i;
}
while (j < len2 && version2.charAt(j) != '.') {
b = b * 10 + version2.charAt(j) - '0';
++j;
}
if (a > b) return 1;
else if (a < b) return -1;
++i;++j;
}
return 0;
}
}
165.比较版本号
最新推荐文章于 2024-08-31 13:48:49 发布