Skip to content

Latest commit

 

History

History
22 lines (20 loc) · 516 Bytes

989.md

File metadata and controls

22 lines (20 loc) · 516 Bytes

989. Add to Array-Form of Integer

Solution 1 (time O(n), space O(1))

class Solution(object):
    def addToArrayForm(self, num, k):
        """
        :type num: List[int]
        :type k: int
        :rtype: List[int]
        """
        ans = []
        for i in range(len(num) - 1, -1, -1):
            k = k + num[i]
            ans.append(k % 10)
            k = k // 10
        while k:
            ans.append(k % 10)
            k = k // 10
        return ans[::-1]