Problem Statement
Pattern:
Solution
public List<Integer> addToArrayForm(int[] num, int k) {
List<Integer> result = new LinkedList<>();
for (int i = num.length - 1; i >= 0; i--) {
// add element to k
k = k + num[i];
// insert last digit to beginning of result
result.add(0, k % 10);
// update k
k /= 10;
}
// copy remaining k
while (k > 0) {
result.add(0, k % 10);
k /= 10;
}
return result;
}