当前位置:网站首页>[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--];
}
}边栏推荐
- Syntax summary of easygui
- Awk from getting started to digging in (23) awk built-in variables argc, argc -- command line parameter transfer
- 快速搭建Dobbo小Demo
- [MySQL series] - how much do you know about the index
- I2C device driver hierarchy
- 没错,请求DNS服务器还可以使用UDP协议
- 牛客多校 E G J L
- Development of uni app offline ID card identification plug-in based on paddleocr
- The concept and operation rules of calculus of variations
- 35 快速格式化代码
猜你喜欢

SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你

Vs2017 large factory ERP management system source code factory general ERP source code

AS查看依赖关系和排除依赖关系的办法

Keys and scan based on redis delete keys with TTL -1

45padding won't open the box

006操作符简介

Heyuan City launched fire safety themed milk tea to boost fire prevention and control in summer

PS making and loading GIF pictures tutorial

Leetcode-198- house raiding

The concept and operation rules of calculus of variations
随机推荐
Filters get the data in data; Filters use data in data
SSH服务器拒绝了密码
基于PaddleOCR开发uni-app离线身份证识别插件
GameFramework制作游戏(一)
苹果官网产品打折 买iPhone 13 Pro Max 可省600元
Flask SSTI injection learning
Writing standard of physical quantities and unit symbols
Niuke multi school E G J L
Kibana operation es
51 single chip microcomputer learning notes (1)
41 图片背景综合-五彩导航图
39 simple version of millet sidebar exercise
Dpkg package download addresses of various platforms (including arm64)
06、类神经网络
How to design a high concurrency system?
I2C设备驱动程序的层次结构
【MySQL系列】-索引知多少
Live classroom system 05 background management system
Jmeter的随机数函数怎么用
The main function of component procurement system, digital procurement helps component enterprises develop rapidly