当前位置:网站首页>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
边栏推荐
- ERROR 1118 (42000): Row size too large (> 8126)
- pytest学习--base
- Metaclass type and using metaclass to implement model class ORM
- Junit5 supports suite methods
- How to judge the quality of primary market projects when the market is depressed?
- Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
- 渗透测试的介绍和防范
- Blender multi lens (multi stand) switching
- Matlab generates DSP program -- official routine learning (6)
- Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
猜你喜欢

滲透測試的介紹和防範

UE4夜间打光笔记

Commutateur Multi - lentilles Blender

Blender石头雕刻

【虚幻4】从U3D到UE4的转型之路
![[Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology](/img/a9/ffd5d8000fc811f958622901bf408d.png)
[Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology

Bookmark collection management software suspension reading and data migration between knowledge base and browser bookmarks

Unreal material editor foundation - how to connect a basic material

测试--面试题总结

阿里云短信服务
随机推荐
Summary of demand R & D process nodes and key outputs
Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
【Lua】常见知识点汇总(包含常见面试考点)
Message mechanism -- getting to know messages and message queues for the first time
Mock Server基本使用方法
How does {} prevent SQL injection? What is its underlying principle?
Project practice, redis cluster technology learning (16)
Blender model import UE, collision settings
【Visual Studio】每次打开一个Unity3D的脚本,都会自动重新打开一个新的VS2017
How to judge the quality of primary market projects when the market is depressed?
Blender石头雕刻
Blender stone carving
SAP Spartacus express checkout design
This monitoring system makes workers tremble: turnover intention and fishing can be monitored. After the dispute, the product page has 404
[Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology
【虚幻】武器插槽:拾取武器
pytest--之测试报告allure配置
Introduction and prevention of penetration test
Translation d30 (with AC code POJ 28:sum number)
Commutateur Multi - lentilles Blender