Skip to content

Latest commit

 

History

History

989-AddtoArray-FormofInteger

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Add to Array-Form of Integer

Problem can be found in here!

def addToArrayForm(nums: List[int], k: int) -> List[int]:
    for i in range(len(nums)-1, -1, -1):
        k, nums[i] = divmod(nums[i]+k, 10)

    return [int(i) for i in str(k)] + nums if k else nums

Time Complexity: O(max(n, logk)), Space Complexity: O(max(n, logk)), where n is the length of array nums.