1.题目描述
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.
给定一个非负整数,表示为一个非空的数字数组,再加上一个整数。
2.题目分析
列表转字符串,字符串转数字,加上整数后转回即可
3.解题思路
class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ num='' #定义空字符串 for i in digits: #列表转字符串(用join函数也可以) num+=(str(i)) digits=int(num) #字符串转数字 digits+=1 #数字加一 digits=str(digits) #转字符串 nums=[] for i in digits: #转列表 nums.append(int(i)) return nums