【leetcode】Merge Sorted Array
题目描述
Given two sorted integer arrays A and B, merge B into A as one sorted array.
Note:
You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.
解题思路:
class Solution:# @param A a list of integers# @param m an integer, length of A# @param B a list of integers# @param n an integer, length of B# @return nothing(void)def merge(self, A, m, B, n):posa = m - 1posb = n - 1for i in range(m+n-1,-1,-1):if posa < 0:A[i] = B[posb]posb -= 1elif posb < 0:returnelif A[posa] > B[posb]:A[i] = A[posa]posa -= 1else:A[i] = B[posb]posb -= 1
转载于:https://www.cnblogs.com/MrLJC/p/4437815.html
【leetcode】Merge Sorted Array相关推荐
- leetcode 88 Merge Sorted Array
lc88 Merge Sorted Array 因为两个array都已经排好序了,每次取两者间较小的放入新array中,当一个array空了,直接把另一个array剩下的全放入新array即可 1 c ...
- LeetCode 之 Merge Sorted Array(排序)
[问题描写叙述] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array ...
- LeetCode之Merge Sorted Array
1.问题 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. No ...
- leetcode 88 Merge Sorted Array
题目描述 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. No ...
- LeetCode 88. Merge Sorted Array
题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Not ...
- LeetCode c++-Merge Sorted Array
题目要求: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. N ...
- 【LeetCode】Merge Two Sorted Lists(合并两个有序链表)
这道题是LeetCode里的第21道题. 题目描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1-&g ...
- 【Leetcode】Shuffle an Array
题目链接:https://leetcode.com/problems/shuffle-an-array/ 题目: Shuffle a set of numbers without duplicates ...
- 【LeetCode】深搜DFS(共85题)
[98]Validate Binary Search Tree [99]Recover Binary Search Tree [100]Same Tree [101]Symmetric Tree [1 ...
最新文章
- 松本行弘:我的编程人生
- qt 拖拽 修改大小
- NSMutableParagraphStyle /NSParagraphStyle
- mysql sock golang_golang thrift 总结一下网络上的一些坑
- Oracle Enterprises Manager 12C安装
- 散列表删除一个元素c语言,分享一个简单高效的哈希表C语言实现
- 让网站和APP更具动感的几点建议
- 挑战malloc极限,看看你的系统有多大的内存分配能力
- Flask-SQLALchemy查询
- 邮箱怎么打开smtp服务器端口号,什么是SMTP协议?SMTP端口号是多少?什么是SMTP服务器?免费smtp服务器?...
- python打印输出如下图形_python题目要求:输出如下图片中的图形
- SQL IF语句的使用
- 手机和工业计算机运算能力对比,手机cpu和电脑cpu差距有多大_手机cpu跟电脑cpu差多少...
- 万字长文:全面解读新公链新生态
- 简述你对人工智能未来发展的看法?
- OpenCV如何进行图像的平滑和锐化处理?
- 一作3篇SCI认定A类博士!享100万安家费+30万科启!三年副教授待遇+2K/月津贴!...
- 关于drawInRect: withAttributes: 等新方法的使用
- uniapp引入dcloud中的组件
- yii2.0.37反序列化漏洞审计
热门文章
- python客户端服务器_Python客户端和服务器ch
- 计算机管理 网络延时打开,如何解决网络延时-如何解决局域网访问延迟问题?通过局域网访问网内机子,有时候半天没 爱问知识人...
- java对账_Java微信对账接口返回值解析
- scala切片_Scala切片功能
- python静态方法_Python静态方法
- scala编程_Scala编程语言简介
- Hibernate Session合并,更新,保存,saveOrUpdate,持久化示例
- java中是值传递引用传递_Java是按值传递而不是按引用传递
- android学习笔记_Intent
- C# DateTime日期格式