(lintcode)第6题 合并排序数组
来源:互联网 发布:手机预算软件 编辑:程序博客网 时间:2024/06/05 19:08
合并两个排序的整数数组A和B变成一个新的数组。
样例
给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6]
public class Solution { /* * @param A: sorted integer array A * @param B: sorted integer array B * @return: A new sorted integer array */ public int[] mergeSortedArray(int[] A, int[] B) { // write your code here int[] C=new int[A.length+B.length]; int i=0,j=0,k=0; while(j<A.length&&k<B.length) { if(A[j]<B[k]){ C[i]=A[j]; i++; j++; }else if(A[j]>B[k]){ C[i]=B[k]; i++; k++; }else if(A[j]==B[k]){ C[i]=A[j]; j++; i++; C[i]=B[k]; i++; k++; } } for(;j<A.length;j++,i++) { C[i]=A[j]; } for(;k<B.length;k++,i++) { C[i]=B[k]; } return C; }}
阅读全文
0 0
- (lintcode)第6题 合并排序数组
- LintCode 6 合并排序数组
- LintCode 合并排序数组
- LintCode: 合并排序数组
- lintcode ----合并排序数组
- LintCode:合并排序数组
- lintcode--合并排序数组
- Lintcode合并排序数组
- Lintcode:合并排序数组
- LintCode之6 合并排序数组
- LintCode 合并排序数组 II
- 合并排序数组(LintCode)
- LintCode(easy)合并排序数组
- LintCode-合并排序数组 II
- 【lintcode笔记】合并排序数组
- Lintcode 合并排序数组 II
- LintCode-合并排序数组 II
- 【LintCode】合并排序数组 II
- POJ1753 Flip Game 位运算+搜索
- apache服务器安装
- 第二章 2.1初级排序算法
- Java虚拟机的发展历史
- 纯CSS设置Checkbox复选框控件的样式和一个今天遇到的用prop给checkbox赋checked属性总是点击两次才能打勾的问题
- (lintcode)第6题 合并排序数组
- 面向对象笔记1
- VS10 C++ 引用第三方库总结
- PHP环境中GD库的开启方法
- Python 中的控制流
- MySQL问题系列---Access denied for user root'@'localhost
- Educational Codeforces Round 27 A—D 题解
- hdu3974 Assign the task(线段树/dfs)(好题)
- WEB服务器为什么取不到用户的MAC地址