当前位置:网站首页>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
边栏推荐
- R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip plot, set the position parameter, and configure the separation degree of different grouped
- LeetCode_ 7_ five
- Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
- openEuler 有奖捉虫活动,来参与一下?
- 如何在软件研发阶段落地安全实践
- 让这个 CRMEB 单商户微信商城系统火起来,太好用了!
- 【STL】vector
- vulnhub之tre1
- 关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】
- Openeuler prize catching activities, to participate in?
猜你喜欢

Welcome to the markdown editor

Implement secondary index with Gaussian redis

Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記

Flink并行度和Slot详解

YoloV6:YoloV6+Win10---训练自己得数据集
让这个 CRMEB 单商户微信商城系统火起来,太好用了!

开源OA开发平台:合同管理使用手册

Cloud component development and upgrading

力扣 2319. 判断矩阵是否是一个 X 矩阵

Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
随机推荐
如何在软件研发阶段落地安全实践
Training IX basic configuration of network services
JVM class loading mechanism
pom.xml 配置文件标签作用简述
How to buy stocks on your mobile phone and open an account? Is it safe to open an account
编译器优化那些事儿(4):归纳变量
国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
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
Semantic slam source code analysis
ASP. Net learning & ASP's one word
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
Throughput
多个线程之间如何协同
力扣 1232.缀点成线
torch. nn. functional. Pad (input, pad, mode= 'constant', value=none) record
Simulate the implementation of string class
Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記
Semantic SLAM源码解析
RESTAPI 版本控制策略【eolink 翻译】
841. 字符串哈希