当前位置:网站首页>[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--];
}
}边栏推荐
- 006 operator introduction
- The concept and operation rules of calculus of variations
- Vs2017 large factory ERP management system source code factory general ERP source code
- [nuxt 3] (XI) transmission & module
- Realsense ROS installation configuration introduction and problem solving
- BIO、NIO、AIO示例
- 51单片机学习笔记(2)
- gson与fastjson
- Is it safe for Guolian securities to buy shares and open an account?
- 直播课堂系统05-后台管理系统
猜你喜欢

基于PaddleOCR开发uni-app离线身份证识别插件

The solution to the problem that the progress bar of ros2 installation connext RMW is stuck at 13%

45padding不会撑开盒子的情况

Syntax summary of easygui

Deng Qinglin, a technical expert of Alibaba cloud: Best Practices for disaster recovery and remote multi activity across availability zones on cloud

51单片机学习笔记(2)

为什么中建、中铁都需要这本证书?究竟是什么原因?

D2. Chopping Carrots (Hard Version) (每日一题)

006操作符简介

D2. picking carrots (hard version) (one question per day)
随机推荐
thymeleaf通过样式控制display是否显示
06. Neural network like
各种平台dpkg包下载地址(包括arm64)
45padding won't open the box
Introduction to PHP
GameFramework制作游戏(一)
OverTheWire-Natas
【cartographer_ros】八: 官方Demo参数配置和效果
Resource not found: rgbd_launch 解决方案
Ten common application scenarios of redis
41 picture background synthesis - colorful navigation map
[Nuxt 3] (十一) 传送 & 模块
44 新浪导航 ,小米边栏 练习
Alibaba cloud installs mysql5.7
EDA chip design solution based on AMD epyc server
Practical guide for network security emergency response technology (Qianxin)
English语法_不定代词 - other / another
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]
IP地址分类,判断一个网段是子网超网
The supply chain collaborative management system, a new "engine" of digitalization in machinery manufacturing industry, helps enterprises' refined management to a new level