BEstyle 2022. 10. 20. 16:18

DESCRIPTION:

Given an array of integers of any length, return an array that has 1 added to the value represented by the array.

  • the array can't be empty
  • only non-negative, single digit integers are allowed

Return nil (or your language's equivalent) for invalid inputs.

Examples

For example the array [2, 3, 9] equals 239, adding one would return the array [2, 4, 0].

[4, 3, 2, 5] would return [4, 3, 2, 6]


 

def up_array(arr):
    alist=[]
    ans=""
    if len(arr)==0:
        return
    for i in arr:
        if i not in range(0,10):
            return
        ans+=str(i)
    ans=int(ans)+1
    for i in range(len(str(ans))):
        alist.append(int(str(ans)[i]))
    return alist