方法1:

 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: void Do not return anything, modify nums1 in-place instead.
"""
while m>0 and n >0:
if nums1[m-1] >= nums2[n-1]:
nums1[m+n-1] = nums1[m-1]
m -= 1
else:
nums1[m+n-1] = nums2[n-1]
n -= 1
if n > 0:
nums1[:n] = nums2[:n]

同上:

 class Solution:
def merge(self, nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: void Do not return anything, modify nums1 in-place instead.
"""
end = m + n -1
m -= 1
n -= 1
while end >= 0 and m >= 0 and n >= 0:
if nums1[m] > nums2[n]:
nums1[end] = nums1[m]
m -= 1
else:
nums1[end] = nums2[n]
n -= 1
end -= 1
while n >= 0:
nums1[end] = nums2[n]
n -= 1
end -= 1

方法3:

 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: void Do not return anything, modify nums1 in-place instead.
"""
nums1[m: m + n] = nums2[: n]
nums1.sort()

最新文章

  1. 给WinForm窗体添加快捷键 响应回车键、空格键
  2. SDK,API,DLL名词解释
  3. 通过3个Hello World应用来了解ASP.NET 5应用是如何运行的(1)
  4. 6-tips-for-managing-property-files-with-spring--转
  5. Codeforces Round #303 (Div. 2) E. Paths and Trees 最短路+贪心
  6. [转贴] C/C++中动态链接库的创建和调用
  7. 删除WIN7系统的共享文件
  8. js变量作用域及访问权限的探讨(2)
  9. [bzoj1783] [Usaco2010 Jan]Taking Turns
  10. codeforces 600E . Lomsat gelral (线段树合并)
  11. Confluence 6 白名单表达式类型
  12. UVA12171-Sculpture(离散化+floodfill)
  13. 利用ant脚本 自动构建svn增量/全量 系统程序升级包【转】
  14. javascript 高级程序设计 九
  15. jbosscache
  16. python---补充locals()变量在变量分发中的使用
  17. Tomcat 多项目管理
  18. swapon和swapoff命令详解
  19. go_接口
  20. postman 上一个接口返回值传给下一个接口

热门文章

  1. Intermediate Python for Data Science learning 3 - Customization
  2. jsp/servlet/mysql/linux基本概念和操作
  3. SQL学习之MYSQL的常用命令和增删改查语句和数据类型
  4. linux 挂载硬盘 + 对硬盘 分区
  5. Thinkphp5 引入第三方类库的方法
  6. 20145122 《Java程序设计》课程总结
  7. 《网络攻防》实验九:web安全基础实践
  8. ms08_067攻击实验
  9. JAVA I/O(一)基本字节和字符IO流
  10. Package libvirt was not found in the pkg-config search path