Problem Statement
You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer.
The digits are ordered from most significant to least significant in left-to-right order.
The large integer does not contain any leading 0's.
Increment the large integer by one and return the resulting array of digits.
Input Specification
The first line of the input gives the number of test cases, , test cases follow. Each test case consists of a line. The line contains the elements of the list which are seperated by space.
Limits
Memory limits: 32MB.
Time limits: 1 second.
The list will not contain any leading zeros.
Test Set 1
Sample Case.
Test Set 2
Test Set 3
Test Set 4
Output Specification
For each test case, output one line containing Case #x: y
, where is the case number(starting from 1), and is the result of adding one to the list .
Sample Input
4
1 2 3
4 3 2 1
9
9 9 9 9
Sample Output
Case #1: [1, 2, 4]
Case #2: [4, 3, 2, 2]
Case #3: [1, 0]
Case #4: [1, 0, 0, 0, 0]
Ref
https://leetcode.com/problems/plus-one/
Hint
for-loop
if-else
Comments