Plus One ( LeetCode ) Problem Solution.
The digits are stored specified the foremost significant figure is at the pinnacle of the list, and every element within the array contain one digit.
You may assume the integer doesn't contain any leading zero, except the amount 0 itself.
Example 1:
Input: [1,2,3] Output: [1,2,4] Explanation: The array represents the integer 123.
Example 2:
Input: [4,3,2,1] Output: [4,3,2,2] Explanation: The array represents the integer 4321.
Solution :-
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
digit=[]
new=[]
for i in digits:
digit.append(str(i))
out=''.join(digit)
out=int(out)+1
digit=list(str(out))
for i in digit:
new.append(int(i))
return new
Runtime: 36 ms, faster than 16.74% of Python3 online submissions for Plus One.
Memory Usage: 13.9 MB, but 5.13% of Python3 online submissions for Plus One.
0 Comments