File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ ##==================================
2
+ ## Leetcode
3
+ ## Student: Vandit Jyotindra Gajjar
4
+ ## Year: 2020
5
+ ## Problem: 66
6
+ ## Problem Name: Plus One
7
+ ##===================================
8
+ #
9
+ #Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
10
+ #
11
+ #The digits are stored such that the most significant digit is at the head of the list,
12
+ #and each element in the array contain a single digit.
13
+ #
14
+ #You may assume the integer does not contain any leading zero, except the number 0 itself.
15
+ #
16
+ #Example 1:
17
+ #
18
+ #Input: [1,2,3]
19
+ #Output: [1,2,4]
20
+ #Explanation: The array represents the integer 123.
21
+ #Example 2:
22
+ #
23
+ #Input: [4,3,2,1]
24
+ #Output: [4,3,2,2]
25
+ #Explanation: The array represents the integer 4321.
26
+ class Solution :
27
+ def plusOne (self , digits ):
28
+ tmpList = [str (i ) for i in digits ] #Initialize tmpList and converting number to string
29
+ tmp = int ('' .join (tmpList )) #Initialize tmp and join the list and converting back to int
30
+ tmp += 1 #Update tmp by adding 1
31
+ return [int (i ) for i in str (tmp )] #Return a list of numbers gained from tmp
You can’t perform that action at this time.
0 commit comments