当前位置:网站首页>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
边栏推荐
- ASP.NET幼儿园连锁管理系统源码
- 使用高斯Redis实现二级索引
- CSDN syntax description
- 九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
- Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
- Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
- PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
- Cloud component development and upgrading
- 位运算介绍
- 【Auto.js】自动化脚本
猜你喜欢
Some important knowledge of MySQL
The project manager's "eight interview questions" is equal to a meeting
Detailed explanation of Flink parallelism and slot
剑指 Offer II 013. 二维子矩阵的和
力扣 599. 两个列表的最小索引总和
BI的边界:BI不适合做什么?主数据、MarTech?该如何扩展?
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
vulnhub之school 1
关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】
LeetCode_ 7_ five
随机推荐
Cuda版本不一致,编译apex报错
R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
JVM GC garbage collection brief
Welcome to the markdown editor
LeetCode_ 7_ five
vulnhub之Funfox2
Mysql, sqlserver Oracle database connection mode
841. String hash
CSDN语法说明
力扣 459. 重复的子字符串
线性基
Training IX basic configuration of network services
转置卷积理论解释(输入输出大小分析)
ASP.NET体育馆综合会员管理系统源码,免费分享
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
力扣 912.排序数组
pom.xml 配置文件标签作用简述
ASP.NET幼儿园连锁管理系统源码
浏览积分设置的目的
mock. JS returns an array from the optional data in the object array