vector plusOne(vector &digits) { int i,j,carry=1; // traditional long addition.. for(i=digits.size()-1;i>=0&&carry;i--){ int sum=carry+digits[i]; carry=sum/10; digits[i]=sum%10; } if(carry){ // if carry is 1, then digits must be all 99..999 digits[0]=1; digits.push_back(0); } return digit
s; }
vector<int> plusOne(vector<int> &digits) {
int i,j,carry=1;
// traditional long addition..
for(i=digits.size()-1;i>=0&&carry;i--){
int sum=carry+digits[i];
carry=sum/10;
digits[i]=sum%10;
}
if(carry){ // if carry is 1, then digits must be all 99..999
digits[0]=1;
digits.push_back(0);
}
return digits;
}
s; }