当前位置:网站首页>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语言dplyr包mutate_at函数和min_rank函数计算dataframe中指定数据列的排序序号值、名次值、将最大值的rank值赋值为1
- Cloud component development and upgrading
- R language dplyr package mutate_ At function and min_ The rank function calculates the sorting sequence number value and ranking value of the specified data column in the dataframe, and assigns the ra
- 【STL】vector
- pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
- ASP. Net kindergarten chain management system source code
- Ucloud is a basic cloud computing service provider
- 9 atomic operation class 18 Rohan enhancement
- Semantic SLAM源码解析
- Welcome to the markdown editor
猜你喜欢
随机推荐
Notes...
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
Compiler optimization (4): inductive variables
RESTAPI 版本控制策略【eolink 翻译】
R language ggplot2 visualization: use the ggecdf function of ggpubr package to visualize the grouping experience cumulative density distribution function curve, and the linetype parameter to specify t
力扣 1790. 仅执行一次字符串交换能否使两个字符串相等
gorilla官方:golang开websocket client的示例代码
Make this crmeb single merchant wechat mall system popular, so easy to use!
# 欢迎使用Markdown编辑器
使用高斯Redis实现二级索引
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
R language dplyr package mutate_ At function and min_ The rank function calculates the sorting sequence number value and ranking value of the specified data column in the dataframe, and assigns the ra
sql 常用优化
mock.js从对象数组中任选数据返回一个数组
[confluence] JVM memory adjustment
IP tools
Implement secondary index with Gaussian redis
力扣 912.排序数组
How to buy bank financial products? Do you need a bank card?
831. KMP字符串








