Can my Python AC code be more efficient?


  • 0
    W
    class Solution:
        # @param digits, a list of integer digits
        # @return a list of integer digits
        def plusOne(self, digits):
            length = len(digits)
    
            while length > 0:
                length -= 1
                digits[length] += 1
                if digits[length] == 10:
                    digits[length] = 0
                else:
                    break
    
            if digits[0] == 0:
                digits.insert(0, 1)
    
            return digits

Log in to reply
 

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