Plus One

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 32M

Author:
Problem type
Allowed languages
Python

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, T, T test cases follow. Each test case consists of a line. The line contains the elements d_i of the list L which are seperated by space.

Limits

Memory limits: 32MB.

Time limits: 1 second.

1 \leq T \leq 100

0 \leq d_i \leq 9

1 \leq \text{length of L} \leq 9

The list will not contain any leading zeros.

Test Set 1

Sample Case.

Test Set 2

1 \leq \text{length of L} \leq 3

Test Set 3

1 \leq \text{length of L} \leq 6

Test Set 4

1 \leq \text{length of L} \leq 9

Output Specification

For each test case, output one line containing Case #x: y, where x is the case number(starting from 1), and y is the result of adding one to the list L.

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

There are no comments at the moment.