当前位置:网站首页>Force buckle 989 Integer addition in array form
Force buckle 989 Integer addition in array form
2022-07-07 20:06:00 【Tomorrowave】
989. The addition of integers in the form of arrays
The integer Array form num Is an array of numbers in left to right order .
for example , about num = 1321 , The array form is [1,3,2,1] .
Given num , The integer Array form , And integer k , return Integers num + k Of Array form .
Knowledge points involved
String conversion
class Solution:
def addToArrayForm(self, A: List[int], K: int) -> List[int]:
K = list(map(int,str(K)))
res = []
i,j = len(A)-1,len(K)-1
carry = 0
while i >= 0 and j >= 0:
res.append(A[i] + K[j] + carry)
res[-1],carry = res[-1] % 10, res[-1] // 10
i -= 1
j -= 1
while i >= 0:
res.append(A[i] + carry)
res[-1],carry = res[-1] % 10, res[-1] // 10
i -= 1
while j >= 0:
res.append(K[j] + carry)
res[-1],carry = res[-1] % 10, res[-1] // 10
j -= 1
if carry:
res.append(1)
return res[::-1]
map() function
in other words ,map You can map the array of this question
del square(x):
return x ** 2
map(square,[1,2,3,4])#[1,4,9,16]
map(int,'1234') #[1,2,3,4]
class Solution:
def addToArrayForm(self, num: List[int], k: int) -> List[int]:
return [int(i) for i in str((int(str(num)[1:-1:3]))+k)]
or:
return list(map(int,str(int(''.join(str(num))) + K)))
边栏推荐
- 银行理财产品怎么买?需要办银行卡吗?
- How to cooperate among multiple threads
- Interpretation of transpose convolution theory (input-output size analysis)
- [RT thread env tool installation]
- equals 方法
- 位运算介绍
- 8 CAS
- 力扣 1790. 仅执行一次字符串交换能否使两个字符串相等
- Openeuler prize catching activities, to participate in?
- Simulate the implementation of string class
猜你喜欢
最多可以参加的会议数目[贪心 + 优先队列]
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
Cloud 组件发展升级
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
Data island is the first danger encountered by enterprises in their digital transformation
模拟实现string类
LeetCode_7_5
The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
mock. JS returns an array from the optional data in the object array
项目经理『面试八问』,看了等于会了
随机推荐
力扣 1790. 仅执行一次字符串交换能否使两个字符串相等
力扣 2319. 判断矩阵是否是一个 X 矩阵
Tp6 realize Commission ranking
R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
Some arrangements about oneself
Semantic SLAM源码解析
ASP. Net learning & ASP's one word
mysql 的一些重要知识
Ways to improve the utilization of openeuler resources 01: Introduction
The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
JVM GC垃圾回收简述
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
力扣599. 两个列表的最小索引总和
数据孤岛是企业数字化转型遇到的第一道险关
8 CAS
pom.xml 配置文件标签作用简述
浏览积分设置的目的
Equals method
Throughput