leetcode.66.PlusOne

 传送门 https://leetcode.com/problems/plus-one/


class Solution(object):
    def plusOne(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        tmp = reduce(lambda x,y:  x * 10 + y, digits) + 1
        return [int(dig) for dig in str(tmp)]
        

if __name__ == '__main__':
	s = Solution()
	alist = [1, 2, 3]
	print alist, s.plusOne(alist)
	alist2 = [4, 3, 2, 1]
	print alist2, s.plusOne(alist2)

 


解题思路: 先将数组转换成对应的10进制数字,+1后,再将每位分拆成数组

原文地址:https://www.cnblogs.com/Wolfanature/p/11440034.html