[LintCode笔记了解一下]64.合并排序数组
Given two sorted integer arrays A and B, merge B into A as one sorted array.
思路:
因为A的后面的部分都是空的留出来给我们放元素,所以最好是从后往前塞元素进去
void mergeSortedArray(int A[], int m, int B[], int n) {
// write your code here
int i = m-;
int j = n-;
int index = m+n-;
while(i>=&&j>=){
if(A[i]>=B[j]){
A[index]=A[i];
index--;
i--;
}else{
A[index]=B[j];
index--;
j--;
}
}
while(i>=){
A[index--]=A[i--];
}
while(j>=){
A[index--]=B[j--];
}
}
[LintCode笔记了解一下]64.合并排序数组的更多相关文章
- 64. 合并排序数组.md
描述 合并两个排序的整数数组A和B变成一个新的数组. 你可以假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B中的元素. 您在真实的面试中是否遇到过这个题? 样例 给出 A = [1, 2, ...
- lintcode:合并排序数组 II
题目: 合并排序数组 II 合并两个排序的整数数组A和B变成一个新的数组. 样例 给出A = [1, 2, 3, empty, empty] B = [4,5] 合并之后A将变成[1,2,3,4,5] ...
- lintcode:合并排序数组
题目: 合并排序数组 合并两个排序的整数数组A和B变成一个新的数组. 样例 给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6] 挑战 你能否优化你的算法,如果 ...
- LintCode之合并排序数组II
题目描述: 分析:题目的意思是把数组A和数组B合并到数组A中,且数组A有足够的空间容纳A和B的元素,合并后的数组依然是有序的. 我的代码: public class Solution { /* * @ ...
- lintcode 中等题:搜索旋转排序数组II
题目 搜索旋转排序数组 II 跟进“搜索旋转排序数组”,假如有重复元素又将如何? 是否会影响运行时间复杂度? 如何影响? 为何会影响? 写出一个函数判断给定的目标值是否出现在数组中. 样例 给出[3, ...
- LintCode——合并排序数组II
描述:合并两个排序的整数数组A和B变成一个新的数组 样例:给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6] 1.Python:先将数组B加到数组A之后,然后 ...
- LintCode之合并排序数组
题目描述: 我的代码: public class Solution { /* * @param A: sorted integer array A * @param B: sorted integer ...
- [LintCode] 合并排序数组II
class Solution { public: /** * @param A: sorted integer array A which has m elements, * but size of ...
- [LintCode] 合并排序数组
A subroutine of merge sort. class Solution { public: /** * @param A and B: sorted integer array A an ...
随机推荐
- Oracle 热备份
Oracle 热备份是指数据库处于open状态下,对数据库的数据文件.控制文件.参数文件.密码文件等进行一系列备份操作. 热备是基于用户管理备份恢复的一种方式,也是除了RMAN备份之外较为常用的一种备 ...
- Centos下Apache+Tomcat集群--搭建记录
一.目的 利用apache的mod_jk模块,实现tomcat集群服务器的负载均衡以及会话复制,这里用到了<Cluster>. 二.环境 1.基础:3台主机,系统Centos6.5,4G内 ...
- Python添加模块
参考博客:http://blog.csdn.net/damotiansheng/article/details/43916881 http://my.oschina.net/leejun2005/bl ...
- OD 实验(十七) - 对一个程序的逆向分析
程序: 运行程序 弹出一个对话框,点击 OK 来到主界面,点击 Help -> Register Now 这是输入注册码的地方 按关闭程序的按钮 会提示剩下 30 天的使用时间 用 Ressco ...
- Springmvc ajax请求400
转载做记录 传JSON对象 前端 function test () { var param = {username : "yitop"}; $.ajax({ timeout : 2 ...
- 分类和逻辑回归(Classification and logistic regression)
分类问题和线性回归问题问题很像,只是在分类问题中,我们预测的y值包含在一个小的离散数据集里.首先,认识一下二元分类(binary classification),在二元分类中,y的取值只能是0和1.例 ...
- nginx作用
图解nginx作用:
- 自适应共振理论网络 ART
引言 自适应共振理论的发源与现状 1976年, 美国 Boston 大学学者 G. A.Carpenter 提出自适应共振理论(Adaptive Res-onance Theory , ART ), ...
- leetcode36
public class Solution { public bool IsValidSudoku(char[,] board) { ; i < ; i++) { var dic = new D ...
- RHCE7 学习里程-1.配置IP,DNS
一.安装系统完成 1.系统安装完成之后不同于 6 的 ifconfig 命令.7 使用ip add ,这个跟网络设备配置端口IP 有点类似. 使用 ip add 查看网卡编号 cd /etc/s ...