Q:

对于非负整数 X 而言,X 的数组形式是每位数字按从左到右的顺序形成的数组。例如,如果 X = 1231,那么其数组形式为 [1,2,3,1]

给定非负整数 X 的数组形式 A,返回整数 X+K 的数组形式

示例 1:

输入:A = [1,2,0,0], K = 34
输出:[1,2,3,4]
解释:1200 + 34 = 1234

链接:https://leetcode-cn.com/problems/add-to-array-form-of-integer/description/

思路:

代码:

class Solution(object):
    def addToArrayForm(self, A, K):
        """
        :type A: List[int]
        :type K: int
        :rtype: List[int]
        """
        return [int(s) for s in (str(int("".join([str(a) for a in A])) + K))]
        

【Leetcode_总结】989. 数组形式的整数加法 - python

相关文章:

  • 2021-04-13
  • 2021-10-20
  • 2021-10-23
  • 2021-04-16
  • 2021-05-06
  • 2021-10-10
  • 2021-12-13
  • 2021-05-11
猜你喜欢
  • 2022-02-04
  • 2021-09-20
  • 2021-08-12
  • 2022-02-08
  • 2021-06-01
  • 2021-06-29
  • 2022-01-04
相关资源
相似解决方案