-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path074. Add One To Number.py
54 lines (34 loc) · 1.34 KB
/
074. Add One To Number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Add One To Number
"""
Problem Description
Given a non-negative number represented as an array of digits, add 1 to the number ( increment the number represented by the digits ).
The digits are stored such that the most significant digit is at the head of the list.
NOTE: Certain things are intentionally left unclear in this question which you should practice asking the interviewer. For example:
for this problem, following are some good questions to ask :
Q : Can the input have 0's before the most significant digit. Or in other words, is 0 1 2 3 a valid input?
A : For the purpose of this question, YES
Q : Can the output have 0's before the most significant digit? Or in other words, is 0 1 2 4 a valid output?
A : For the purpose of this question, NO. Even if the input has zeroes before the most significant digit.
Input Format
First argument is an array of digits.
Output Format
Return the array of digits after adding one.
Example Input
Input 1:
[1, 2, 3]
Example Output
Output 1:
[1, 2, 4]
Example Explanation
Explanation 1:
Given vector is [1, 2, 3].
The returned vector should be [1, 2, 4] as 123 + 1 = 124.
"""
class Solution:
# @param A : list of integers
# @return a list of integers
def plusOne(self, A):
out = int("".join(map(str,A)))
out += 1
lst = [int(x) for x in str(out)]
return (lst)