将两个递增序列合并,如果简单地使用二重循环,则时间复杂度为O(n*m),当序列很大时会崩溃,但是采用two pointers算法可以将时间复杂度减少为O(n+m),代码如下
输入:
3 5
1 3 5
2 4 5 6 7
代码如下:
#include<stdio.h>
using namespace std;
const int maxn = 100;
int a[maxn] = {
0};
int b[maxn] = {
0};
int c[maxn+maxn] =
将两个递增序列合并,如果简单地使用二重循环,则时间复杂度为O(n*m),当序列很大时会崩溃,但是采用two pointers算法可以将时间复杂度减少为O(n+m),代码如下
输入:
3 5
1 3 5
2 4 5 6 7
代码如下:
#include<stdio.h>
using namespace std;
const int maxn = 100;
int a[maxn] = {
0};
int b[maxn] = {
0};
int c[maxn+maxn] =