C++ Reverse
Reverse the string first to simplify things. Then add numbers left to rigth, and mind the overflow.\n\nIf needed, add an extra character to the end of the strin
Reverse the string first to simplify things. Then add numbers left to rigth, and mind the overflow.\n\nIf needed, add an extra character to the end of the string. Since the string is reversed, adding a character does not require shifting the whole string.\n\nIn the end, reverse the string back.\n```\nvector<int> addToArrayForm(vector<int>& A, int K) {\n  reverse(begin(A), end(A));\n  for (size_t i = 0; K > 0; K /= 10, ++i) {\n    A.resize(max(i + 1, A.size()));\n    if ((A[i] += K % 10) >= 10) {\n      A[i] -= 10;\n      K += 10;\n    }\n  }\n  reverse(begin(A), end(A));\n  return A;\n}\n```
[]