Simple python solution with explanation


  • 0
    B

    My idea is to use the type conversion.
    list->str->int->int+1->str->list.

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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.