Add One To Number in array code example
Example: Add One To Number in array
vector<int> Solution::plusOne(vector<int> &a) { int n=a[a.size()-1]+1; vector<int> r; r.push_back(n%10); int carry=n/10; if(carry==0) { a[a.size()-1]++; return a; } for(int i=a.size()-2; i>=0; i--) { n=a[i]+carry; carry=n/10; r.push_back(n%10); } reverse(r.begin(),r.end()); return r;}XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX