力扣165比较版本号原题链接
AC代码:
class Solution {
public:
int compareVersion(string v1, string v2) {
int i = 0, j = 0;
while(i<v1.size() || j<v2.size())
{
int num1 = 0,num2 = 0;
while(i<v1.size() && v1[i]!='.')
{
num1 = num1 *10 + v1[i]-'0';
i++;
}
while(j<v2.size()&&v2[j]!='.')
{
num2 = num2 * 10 + v2[j] - '0';
j++;
}
if(num1 > num2) return 1;
else if(num1 < num2) return -1;
//else reutrn 0; //未比完,1.0.1 与 1
i++;
j++;
}
return 0;
}
};