标签:number color dig 加法 div amp present plus one tco
#66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
题解:模拟加法运算就好了。
class Solution { public: vector<int> plusOne(vector<int>& digits) { int c=1; for(int i=digits.size()-1;i>=0;i--) { int sum=digits[i]+c; c=sum/10; digits[i]=sum%10; } if(c==1) { digits.insert(digits.begin(),1); } return digits; } };
标签:number color dig 加法 div amp present plus one tco
原文地址:http://www.cnblogs.com/fengxw/p/6086066.html