Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.

You may assume the integer do not contain any leading zero, except the number 0 itself.

The digits are stored such that the most significant digit is at the head of the list.

 

 1 class Solution(object):
 2     def plusOne(self, digits):
 3         """
 4         :type digits: List[int]
 5         :rtype: List[int]
 6         """
 7         
 8         num = 0
 9         for i in range(len(digits)):
10             num = num*10+digits[i]
11         return [int(i) for i in str(num+1)]
12             

先将digits转换成数字,加1,然后再转换成列表

posted on 2017-03-14 15:48  Ci_pea  阅读(158)  评论(0)    收藏  举报