class Solution {
public:
vector<int> plusOne(vector<int> &digits){
int count = digits.size();
digits[count-1] += 1;
while(count--){
if(digits[count] >=10 && count >=1){
digits[count] %= 10;
digits[count-1] +=1;
}
}
if(digits[0]>=10){
vector<int> result;
result.push_back(1);
result.push_back(digits[0]%10);
for (int i = 1; i < digits.size(); i ++)
{
result.push_back(digits[i]);
}
return result;
}
else
return digits;
}
};
Plus One
最新推荐文章于 2021-08-21 12:48:52 发布