当前位置:网站首页>Force buckle 88 Merge two ordered arrays
Force buckle 88 Merge two ordered arrays
2022-07-07 20:06:00 【Tomorrowave】
88. Merge two ordered arrays
Here are two buttons Non decreasing order Array of arranged integers nums1 and nums2, There are two other integers m and n , respectively nums1 and nums2 The number of elements in .
Would you please Merge nums2 To nums1 in , Make the merged array press Non decreasing order array .
Be careful : Final , The merged array should not be returned by the function , It's stored in an array nums1 in . In response to this situation ,nums1 The initial length of is m + n, The top m Elements represent the elements that should be merged , after n Elements are 0 , It should be ignored .nums2 The length of is n .
Example 1:
Input :nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
Output :[1,2,2,3,5,6]
explain : Need merger [1,2,3] and [2,5,6] .
The combined result is [1,2,2,3,5,6] , In which, bold italics indicates nums1 The elements in
Ideas
a = [1,2,3,4,7,5,6]
b = ['a','b']
c = ['h',12,'c']
a.extend(b)
a.extend(c)
print(a)
# result :[1, 2, 3, 4, 7, 5, 6, 'a', 'b', 'h', 12, 'c']
from numpy import array
a = [1,2,3]
b = ['a','b','c']
c = ['h',12,'k']
e = [a,b,c]
e = array(e)
print(e.flatten())
# result :['1' '2' '3' 'a' 'b' 'c' 'h' '12' 'k']
a = [1,2,3,4] # The number of elements is different
b = ['a','b','c']
c = ['h',12,'k']
e = [a,b,c]
e = array(e)
print(e.flatten())
# result :[list([1, 2, 3, 4]) list(['a', 'b', 'c']) list(['h', 12, 'k'])]
The merging process of arrays
Code section
class Solution:
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
""" Do not return anything, modify nums1 in-place instead. """
nums1[m:] = nums2
nums1.sort()
return nums1
边栏推荐
- Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse
- 开源重器!九章云极DataCanvas公司YLearn因果学习开源项目即将发布!
- 编译器优化那些事儿(4):归纳变量
- Notes...
- LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
- 使用高斯Redis实现二级索引
- mock. JS returns an array from the optional data in the object array
- 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!!!
- Open source heavy ware! Chapter 9 the open source project of ylarn causal learning of Yunji datacanvas company will be released soon!
- pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
猜你喜欢
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
Implement secondary index with Gaussian redis
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
Detailed explanation of Flink parallelism and slot
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
# 欢迎使用Markdown编辑器
Open source heavy ware! Chapter 9 the open source project of ylarn causal learning of Yunji datacanvas company will be released soon!
PMP practice once a day | don't get lost in the exam -7.7
【STL】vector
随机推荐
The project manager's "eight interview questions" is equal to a meeting
Detailed explanation of Flink parallelism and slot
Openeuler prize catching activities, to participate in?
力扣 599. 两个列表的最小索引总和
【剑指offer】剑指 Offer II 012. 左右两边子数组的和相等
JVM GC垃圾回收简述
毕业季|遗憾而又幸运的毕业季
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
sql 常用优化
How to buy stocks on your mobile phone and open an account? Is it safe to open an account
干货分享|DevExpress v22.1原版帮助文档下载集合
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
【STL】vector
力扣 459. 重复的子字符串
如何在软件研发阶段落地安全实践
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
Browse the purpose of point setting
831. KMP string
# 欢迎使用Markdown编辑器
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!