LeetCode 989. Integer addition in the form of an array
I don't know where I am going, but I am already on my way!
Time is hurried, although I have never met, but I met Yusi, it is really a great fate, thank you for your visit!
Question : For non-negative integer X, the array form of X is an array formed by each digit in the order from left to right. For example, if X = 1231, then its array form is [1,2,3,1]. Given the array form A of the non-negative integer X, return the array form of the integer X+K.
classSolution:defaddToArrayForm(self, A: List[int], K:int)-> List[int]:
s =''
a =[]for i inrange(len(A)):
s +=str(A[i])
q =int(s)+ K
for i instr(q):
a.append(int(i))return a
# 执行用时 : 280 ms, 在Add to Array-Form of Integer的Python3提交中击败了43.75% 的用户# 内存消耗 : 13.5 MB, 在Add to Array-Form of Integer的Python3提交中击败了100.00% 的用户
Algorithm description: Convert an array to a string, convert a string to an integer, perform an addition operation, then convert the addition result into a string, and then output the string as an array.