Python describes leetcode 88. Merging two ordered arrays

Qi Guanjie 2021-04-06 14:31:14
python describes leetcode merging ordered


Python describe LeetCode 88. Merge two ordered arrays

Hello everyone , My name is Qi Guanjie (qí guān jié ), stay GitHub & CSDN Record the process of learning , Time flies , Future period , come on. ~ Bloggers are only in GitHub & CSDN Chinese blog , The only blog update address is : Qi Guanjie's blog , In the near future, we will gradually synchronize the relevant records to GitHub:[Algorithmic-learning-records] (https://github.com/qiguanjie/Algorithmic-learning-records), Most of them are my records , If reprinted, please attach the original address , thank you .


Due to the need of study and work , Algorithm brush problem will gradually change from C++ towards Python3 excessive , In transition , If the implementation is not very beautiful , Please forgive me .

This article was originally written by Qi Guanjie , Please support the original , Some platforms have been stealing blog articles maliciously !!!
If you need to contact the blogger , You can contact me on wechat :qiguanjie2015


Here are two arrays of ordered integers nums1 and nums2, Would you please nums2 Merge into nums1 in *,* send nums1 Make an ordered array .

initialization nums1 and nums2 The number of elements of is m and n . You can assume nums1 The size of the space is equal to m + n, So that it has enough space to hold from nums2 The elements of .

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]

Example 2:

 Input :nums1 = [1], m = 1, nums2 = [], n = 0
Output :[1]

Tips :

  • nums1.length == m + n
  • nums2.length == n
  • 0 <= m, n <= 200
  • 1 <= m + n <= 200
  • -109 <= nums1[i], nums2[i] <= 109

Algorithm implementation

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()
版权声明
本文为[Qi Guanjie]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/04/20210406142738292l.html

  1. Docker | 多图预警 | 配置Docker下Python开发环境
  2. Docker | multi graph warning | configuring Python development environment under docker
  3. 课程学习记录之python迭代器和生成器
  4. Python_学习之流程控制
  5. Python_学习之运算符
  6. Python_学习之基础数据类型
  7. Python_学习之虚拟环境的搭建
  8. Python iterator and generator of course learning record
  9. Python_ Process control of learning
  10. Python_ Learning operators
  11. Python_ Basic data types of learning
  12. Python_ The construction of virtual learning environment
  13. 一个非常简单好用的 Python 图形界面库
  14. 我就是这样学 Python 的
  15. 零基础,从一个抢票程序,提升自己的Python技能
  16. A very simple and easy to use Python graphical interface library
  17. That's how I learned python
  18. 商业数据分析从入门到入职(9)Python网络数据获取
  19. Zero basis, improve your Python skills from a ticket grabbing program
  20. 商业数据分析从入门到入职(8)Python模块、文件IO和面向对象
  21. 商业数据分析从入门到入职(7)Python基础数据结构及其操作
  22. 商业数据分析从入门到入职(6)Python程序结构和函数
  23. Business data analysis from entry to entry (9) Python Network Data Acquisition
  24. Business data analysis from entry to entry (8) Python module, file IO and object oriented
  25. Business data analysis from entry to entry (7) Python basic data structure and its operation
  26. Business data analysis from entry to entry (6) Python program structure and function
  27. 简简单单实现 Python Web 的登录注册页面,还包含一半逻辑。
  28. Simple implementation of Python web login registration page, but also contains half of the logic.
  29. 什么是pip?Python新手入门指南
  30. What is PIP? Getting started with Python
  31. Python uses for... Else to jump out of double nested loop
  32. Python基础之:Python中的内部对象
  33. 人工智能入门:Python实现机器学习
  34. The foundation of Python: inner objects in Python
  35. Introduction to artificial intelligence: machine learning in Python
  36. Python基础之:Python中的内部对象
  37. The foundation of Python: inner objects in Python
  38. Python 小技之 Office 文件转 PDF
  39. 还在为多张Excel汇总统计发愁?Python 秒处理真香!
  40. 用 Python 制作音乐聚合下载器
  41. Spark Delta Lake 0.4.0 发布,支持 Python API 和部分 SQL
  42. How to transfer office files to PDF
  43. Are you still worried about multiple excel summary statistics? Python second processing really fragrant!
  44. Making music aggregate downloader with Python
  45. Spark delta Lake 0.4.0 is released, supporting Python API and part of SQL
  46. Python信息搜集
  47. Python information gathering
  48. Python - 关于类(self/cls) 以及 多进程通讯的思考
  49. Python - thinking about class (self / CLS) and multi process communication
  50. Python - 关于类(self/cls) 以及 多进程通讯的思考
  51. Python - thinking about class (self / CLS) and multi process communication
  52. Python信用评分卡建模(附代码)
  53. Python credit score card modeling (with code)
  54. 学Python需要学数据库吗?Python学习教程!
  55. Do you need to learn database to learn Python!
  56. Python私有变量如何定义?Python学习教程!
  57. How to define Python private variables? Python tutorial!
  58. Python数据分析入门(六):Pandas的函数应用
  59. Introduction to Python data analysis (6): function application of pandas
  60. 学Python需要学数据库吗?Python学习教程!