当前位置:网站首页>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
边栏推荐
- [ue5] two implementation methods of AI random roaming blueprint (role blueprint and behavior tree)
- Mobile mall app solution: how much is it to make an app? Detailed explanation of APP mall development content
- Blender camera surround motion, animation rendering, video synthesis
- 【Lua】常见知识点汇总(包含常见面试考点)
- pytest框架实现前后置
- 两数之和,求目标值
- 职业规划和发展
- 【教程】如何让VisualStudio的HelpViewer帮助文档独立运行
- 【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
- Summary of demand R & D process nodes and key outputs
猜你喜欢
![[illusory] weapon slot: pick up weapons](/img/a7/1e395fc9cdfd0359e7ae4d2313290d.png)
[illusory] weapon slot: pick up weapons

【UE5】动画重定向:如何将幻塔人物导入进游戏玩耍

Summary of demand R & D process nodes and key outputs

测试--面试题总结

Mock Server基本使用方法

2837xd code generation module learning (1) -- GPIO module

阿里云SLS日志服务

Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer

Commutateur Multi - lentilles Blender

虚幻AI蓝图基础笔记(万字整理)
随机推荐
What wires are suitable for wiring on bread board?
【Visual Studio】每次打开一个Unity3D的脚本,都会自动重新打开一个新的VS2017
ue虛幻引擎程序化植物生成器設置——如何快速生成大片森林
VLAN experiment
Junit4运行mvn test 测试套件升级方案
判断数组中是否存在重复元素
[unreal] key to open the door blueprint notes
【虚幻】武器插槽:拾取武器
The primary market project galaxy will conduct public offering on coinlist on February 17
【虚幻】按键开门蓝图笔记
2837xd code generation module learning (1) -- GPIO module
Project practice, redis cluster technology learning (IX)
[Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology
【UE5】AI随机漫游蓝图两种实现方法(角色蓝图、行为树)
Translation d30 (with AC code POJ 28:sum number)
Database -- acid of transaction -- introduction / explanation
How to achieve the top progress bar effect in background management projects
【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
MySQL transaction
【虚幻】自动门蓝图笔记