当前位置:网站首页>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)))
边栏推荐
- Sword finger offer II 013 Sum of two-dimensional submatrix
- vulnhub之school 1
- 国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
- 让这个 CRMEB 单商户微信商城系统火起来,太好用了!
- Introduction to bit operation
- 【Confluence】JVM内存调整
- [auto.js] automatic script
- Training IX basic configuration of network services
- How to cooperate among multiple threads
- The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
猜你喜欢
随机推荐
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
pom.xml 配置文件标签作用简述
R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
Visual Studio 插件之CodeMaid自动整理代码
Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
Time tools
JVM class loading mechanism
R language uses ggplot2 function to visualize the histogram distribution of counting target variables that need to build Poisson regression model, and analyzes the feasibility of building Poisson regr
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
How to buy stocks on your mobile phone and open an account? Is it safe to open an account
J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
【Confluence】JVM内存调整
R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
SQL common optimization
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
R language dplyr package mutate_ At function and min_ The rank function calculates the sorting sequence number value and ranking value of the specified data column in the dataframe, and assigns the ra
R language ggplot2 visualization: use the ggecdf function of ggpubr package to visualize the grouping experience cumulative density distribution function curve, and the linetype parameter to specify t
【STL】vector
多个线程之间如何协同
微信公众号OAuth2.0授权登录并显示用户信息