LeetCode--Python解析【Plus One】(66)

题目:


方法:

很简单的一道题,时间复杂度为O(n),首先将数组转换为数字,加一后再转换回数组,最后返回,结束。

其中对数组进行了str到int的两次转换。

class Solution(object):
    def plusOne(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        num = str()
        res = []
        for n in digits:
            num += str(n)
        num = int(num)
        num += 1
        num = str(num)
        res = [int(n) for n in num]
        return res


猜你喜欢

转载自blog.csdn.net/ZJRN1027/article/details/80353408
今日推荐