当前位置:网站首页>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
边栏推荐
- 【Confluence】JVM内存调整
- 小试牛刀之NunJucks模板引擎
- 【Auto.js】自动化脚本
- Data island is the first danger encountered by enterprises in their digital transformation
- Detailed explanation of Flink parallelism and slot
- openEuler 有奖捉虫活动,来参与一下?
- 力扣 2319. 判断矩阵是否是一个 X 矩阵
- 841. String hash
- Openeuler prize catching activities, to participate in?
- 开源重器!九章云极DataCanvas公司YLearn因果学习开源项目即将发布!
猜你喜欢
关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】
The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
9 atomic operation class 18 Rohan enhancement
模拟实现string类
ASP.NET幼儿园连锁管理系统源码
openEuler 有奖捉虫活动,来参与一下?
ASP.NET学习& asp‘s one word
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
Ways to improve the utilization of openeuler resources 01: Introduction
随机推荐
LeetCode_ 7_ five
mysql 的一些重要知识
tp6 实现佣金排行榜
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
线性基
[sword finger offer] sword finger offer II 012 The sum of left and right subarrays is equal
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
Some important knowledge of MySQL
LeetCode力扣(剑指offer 36-39)36. 二叉搜索树与双向链表37. 序列化二叉树38. 字符串的排列39. 数组中出现次数超过一半的数字
力扣 2319. 判断矩阵是否是一个 X 矩阵
IP 工具类
力扣 989. 数组形式的整数加法
转置卷积理论解释(输入输出大小分析)
力扣674. 最长连续递增序列
Data island is the first danger encountered by enterprises in their digital transformation
力扣 599. 两个列表的最小索引总和
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize the violin diagram, set the palette parameter to customize the filling color of violin diagrams at different
力扣 2315.统计星号
力扣 1790. 仅执行一次字符串交换能否使两个字符串相等