当前位置:网站首页>Merge ordered sequence
Merge ordered sequence
2022-07-02 10:21:00 【Lost ~ know to return】
Ordered sequence after merging
Merge ordered sequence
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
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/merge-sorted-array
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Knowledge point ;
Array :
Advanced features of lists , section
Personal thinking :
- Delete nums1 Array 0 Elements
- add to nums2 Elements in to nums1 in
- nums1 call sort Method to sort the new array
In the delete 0 In the process of element ,nums1 Last of 0 The element has never been deleted
class Solution(object):
def merge(self, nums1, m, nums2, n):
""" :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :rtype: None Do not return anything, modify nums1 in-place instead. """
# nums1[m:] = nums2
# nums1.sort()
# print nums1
for i in range(n):
nums1.append(nums2[i])
print nums1
l = len(nums1)
print l
for i in range(l):
print (i, nums1[i])
if nums1[i] == 0:
nums1.pop(i)
nums1.sort()
Solution 1 :
Use the advanced features of functions : List slice
class Solution(object):
def merge(self, nums1, m, nums2, n):
""" :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :rtype: None Do not return anything, modify nums1 in-place instead. """
nums1[m:]=nums2
nums1.sort()
Direct merger :nums1 and nums2
m Express nums1 Middle Africa 0 Number of elements
n Express nums2 Middle Africa 0 Number of elements
take nums1 in m Post position 0 Element direct use nums2 Element replacement in
Time complexity : The time complexity can be calculated according to the quick sorting
边栏推荐
- MySQL index
- Alibaba cloud SMS service
- Metaclass type and using metaclass to implement model class ORM
- Spatial interpretation | comprehensive analysis of spatial structure of primary liver cancer
- 阿里云短信服务
- 2837xd代码生成模块学习(1)——GPIO模块
- Mobile mall app solution: how much is it to make an app? Detailed explanation of APP mall development content
- Project practice, redis cluster technology learning (12)
- 虚幻——动画蓝图、状态机制作人物走跑跳动作
- Blender multi lens (multi stand) switching
猜你喜欢

Network real-time video streaming based on OpenCV

阿里云ack介绍

pytest框架实现前后置

Blender camera surround motion, animation rendering, video synthesis

2837xd代码生成模块学习(1)——GPIO模块

Leetcode -- the nearest common ancestor of 236 binary tree
Brief analysis of edgedb architecture

Applet development summary

2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?

2021-10-02
随机推荐
pytest框架实现前后置
Blender体积雾
Blender海洋制作
Basic notes of illusory AI blueprint (10000 words)
07数据导入Sqoop
滲透測試的介紹和防範
渗透测试的介绍和防范
MySQL index
Operator exercises
Vscode auto format
Project practice, redis cluster technology learning (IX)
阿里云ack介绍
Project practice, redis cluster technology learning (6)
UE4 night lighting notes
Commutateur Multi - lentilles Blender
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Translation d30 (with AC code POJ 28:sum number)
[ue5] two implementation methods of AI random roaming blueprint (role blueprint and behavior tree)
The primary market project galaxy will conduct public offering on coinlist on February 17
【虚幻】过场动画笔记