当前位置:网站首页>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
- How does {} prevent SQL injection? What is its underlying principle?
- Translation d30 (with AC code POJ 28:sum number)
- Nonlinear optimization: establishment of slam model
- 【避坑指南】使用UGUI遇到的坑:Text组件无法首行缩进两格
- Skywalking理论与实践
- Summary of demand R & D process nodes and key outputs
- Mock Server基本使用方法
- 【虚幻】过场动画笔记
- pytest学习--base
猜你喜欢
UE5——AI追逐(藍圖、行為樹)
Aiphacode is not a substitute for programmers, but a tool for developers
2837xd代码生成模块学习(3)——IIC、eCAN、SCI、Watchdog、eCAP模块
Introduction and Principle notes of UE4 material
pytest--之测试报告allure配置
Applet development summary
Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
2021-10-02
Junit5 支持suite的方法
【虚幻】按键开门蓝图笔记
随机推荐
Feature (5): how to organize information
A model can do two things: image annotation and image reading Q & A. VQA accuracy is close to human level | demo can be played
阿里云Prometheus监控服务
Matlab代码生成之SIL/PIL测试
Following nym, the new project Galaxy token announced by coinlist is gal
07数据导入Sqoop
虚幻——动画蓝图、状态机制作人物走跑跳动作
滲透測試的介紹和防範
Project practice, redis cluster technology learning (VIII)
【Lua】常见知识点汇总(包含常见面试考点)
【虚幻4】从U3D到UE4的转型之路
阿里云ack介绍
网络通信学习
Unreal material editor foundation - how to connect a basic material
pytest学习--base
【UE5】AI随机漫游蓝图两种实现方法(角色蓝图、行为树)
[unreal] animation notes of the scene
2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
Introduction and Principle notes of UE4 material
2837xd code generation module learning (1) -- GPIO module