leetcode.66.PlusOne

喜欢而已 提交于 2019-11-29 02:17:10

 传送门 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后,再将每位分拆成数组

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!