class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 比较版本号
* @param version1 string字符串
* @param version2 string字符串
* @return int整型
*/
int compare(string version1, string version2) {
int len1 = version1.size(), len2 = version2.size();
int len1Index = 0, len2Index = 0, v1Num = 0, v2Num = 0;
while (len1Index < len1 || len2Index < len2) {
v1Num = 0, v2Num = 0;
while(version1[len1Index] != '.' && len1Index < len1) {
v1Num *= 10;
v1Num += version1[len1Index] - '0';
len1Index++;
}
while(version2[len2Index] != '.' && len2Index < len2) {
v2Num *= 10;
v2Num += version2[len2Index] - '0';
len2Index++;
}
if (v1Num > v2Num) {
return 1;
} else if (v1Num < v2Num) {
return -1;
}
len1Index++, len2Index++;
}
return 0;
// write code here
}
};