Plus One - LeetCode
题目:
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
分析:本题考验数字存储,即是把list数字组合加一后再分散存储成list。
代码:
class Solution:
# @param digits, a list of integer digits
# @return a list of integer digits
def plusOne(self, digits):
digit = [str(i) for i in digits]
res = ''.join(digit)
res1 = []
for i in str(1+int(res)):
res1.append(int(i))
return res1