adding numbers within an array code example
Example 1: adding numbers in an array javascript
console.log(
[].reduce((a, b) => a + b)
)
Example 2: 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