当前位置:网站首页>[C题目]力扣88. 合并两个有序数组
[C题目]力扣88. 合并两个有序数组
2022-07-25 14:44:00 【GLC8866】
思路:比较nums1和nums2两个数组最后一个元素的大小,数值大的元素赋值到nums1数组最后一个空位,重复以上操作,直到nums2数组中的元素全部赋值到nums1后结束程序。
void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n)
{
int m1=m-1;
int n1=n-1;
int mn1=nums1Size-1;
while(n1>=0&&m1>=0)//两个数组中都还有元素时进入循环
{
if(nums1[m1]>nums2[n1])
{
nums1[mn1]=nums1[m1];
mn1--;
m1--;
}
else
{
nums1[mn1]=nums2[n1];
mn1--;
n1--;
}
}
while(n1>=0)//nums2数组还有元素没有赋值完时进入循环
{
nums1[mn1--]=nums2[n1--];
}
}边栏推荐
- 45padding won't open the box
- 微信公众号正式环境上线部署,第三方公众平台接入
- Why do China Construction and China Railway need this certificate? What is the reason?
- 用GaussDB(for Redis)存画像,推荐业务轻松降本60%
- 006操作符简介
- 006 operator introduction
- GameFramework制作游戏(二)制作UI界面
- Several methods of spark parameter configuration
- QObject源码剖析-d指针和q指针
- L1和L2正则化
猜你喜欢

Melodic + Realsense D435i 配置及错误问题解决

45padding won't open the box

filters获取data中的数据;filters使用data中的数据
![[eloquence] negotiation persuasion skills and Strategies](/img/01/0fcbbfcf35a6d166c14ba4215eacac.jpg)
[eloquence] negotiation persuasion skills and Strategies

冈萨雷斯 数字图像处理 第一章绪论

Products on Apple's official website can save 600 yuan by buying iPhone 13 Pro max at a discount
![[MySQL series] - how much do you know about the index](/img/d7/5045a846580be106e2bf16d7b30581.png)
[MySQL series] - how much do you know about the index

Under the epidemic, the biomedical industry may usher in breakthrough development

sudo rosdep init Error ROS安装问题解决方案

【口才】谈判说服技巧及策略
随机推荐
PHP 通过原生CURL实现非阻塞(并发)请求模式
thymeleaf设置disabled
Go language founder leaves Google
06、类神经网络
spark参数调整调优
Gameframework making games (II) making UI interface
51 single chip microcomputer learning notes (1)
kibana操作es
物理量与单位符号的书写标准
32 chrome调试工具的使用
Is it safe for Guolian securities to buy shares and open an account?
Resource not found: rgbd_launch 解决方案
Gameframework making games (I)
06. Neural network like
Examples of bio, NiO, AIO
OverTheWire-Natas
Melody + realsense d435i configuration and error resolution
[nuxt 3] (XI) transmission & module
Several methods of spark parameter configuration
37 element mode (inline element, block element, inline block element)