当前位置:网站首页>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)))
边栏推荐
- BI的边界:BI不适合做什么?主数据、MarTech?该如何扩展?
- 力扣 1037.有效的回旋镖
- 让这个 CRMEB 单商户微信商城系统火起来,太好用了!
- 【Auto.js】自动化脚本
- 关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】
- 模拟实现string类
- torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
- Visual Studio 插件之CodeMaid自动整理代码
- LeetCode_7_5
- R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
猜你喜欢
Sword finger offer II 013 Sum of two-dimensional submatrix
Introduction to bit operation
CSDN语法说明
[RT thread env tool installation]
Openeuler prize catching activities, to participate in?
# 欢迎使用Markdown编辑器
vulnhub之school 1
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!!!
PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!
9 atomic operation class 18 Rohan enhancement
随机推荐
力扣 88.合并两个有序数组
torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
Implement secondary index with Gaussian redis
LeetCode_7_5
力扣 1790. 仅执行一次字符串交换能否使两个字符串相等
vulnhub之tre1
Sword finger offer II 013 Sum of two-dimensional submatrix
Open source heavy ware! Chapter 9 the open source project of ylarn causal learning of Yunji datacanvas company will be released soon!
浏览积分设置的目的
力扣 1232.缀点成线
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!!!
tp6 实现佣金排行榜
Boot 和 Cloud 的版本选型
项目经理『面试八问』,看了等于会了
pom. Brief introduction of XML configuration file label function
RESTAPI 版本控制策略【eolink 翻译】
UCloud是基础云计算服务提供商
openEuler 资源利用率提升之道 01:概论
R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
Leetcode force buckle (Sword finger offer 36-39) 36 Binary search tree and bidirectional linked list 37 Serialize binary tree 38 Arrangement of strings 39 Numbers that appear more than half of the tim