LeetCode——加一
vector<int> plusOne(vector<int>& digits) {
int length = digits.size();
int focus = length - 1;
digits[focus] += 1;
while(digits[focus] == 10 & focus > 0) //focus位是否进位
{
digits[focus] = 0;
focus--;
digits[focus] += 1;
}
if(digits[0] != 10) //0位是否为10
//if(digits[focus] != 10) //逻辑相同 更快
return digits;
else //对应所有数值均为9.如[9,9,9,9]
{
vector<int> num{1};
while(length--)
num.push_back(0);
return num;
}
}