当前位置:网站首页>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 buy bank financial products? Do you need a bank card?
- PMP每日一练 | 考试不迷路-7.7
- 力扣599. 两个列表的最小索引总和
- sql 常用优化
- 力扣674. 最长连续递增序列
- Version selection of boot and cloud
- pom. XML configuration file label: differences between dependencies and dependencymanagement
- R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
- The DBSCAN function of FPC package of R language performs density clustering analysis on data, checks the clustering labels of all samples, and the table function calculates the two-dimensional contin
- Semantic slam source code analysis
猜你喜欢
随机推荐
Nunjuks template engine
R language ggplot2 visualization: use the ggdensity function of ggpubr package to visualize the packet density graph, and use stat_ overlay_ normal_ The density function superimposes the positive dist
9 原子操作类之18罗汉增强
Boot 和 Cloud 的版本选型
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
关于自身的一些安排
pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
SQL common optimization
Mysql, sqlserver Oracle database connection mode
[RT thread env tool installation]
How to buy stocks on your mobile phone and open an account? Is it safe to open an account
多个线程之间如何协同
IP 工具类
PMP practice once a day | don't get lost in the exam -7.7
ASP.NET幼儿园连锁管理系统源码
openEuler 有奖捉虫活动,来参与一下?
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字
Some arrangements about oneself









