当前位置:网站首页>In situ merging of two arrays with two pointers
In situ merging of two arrays with two pointers
2022-06-30 14:37:00 【Douglas_ LT】
A daily topic ing, Today is a day easy topic 88. Merge Sorted Array
class Solution {
public:
void merge(vector<int>& nums1, int m, vector<int>& nums2, int n)
{
int pos=nums1.size()-1;
int i=m-1,j=n-1;
while(i>=0&&j>=0)
{
int temp=max(nums1[i],nums2[j]);
if(nums1[i]>nums2[j]) i--;
else j--;
nums1[pos]=temp;
pos--;
}
while(j>=0&&pos>=0){
nums1[pos]=nums2[j];
j--;pos--;
}
}
};
边栏推荐
- Use of laravel repository mode
- @ResponseBody的作用
- Details of gets, fgetc, fgets, Getc, getchar, putc, fputc, putchar, puts, fputs functions
- JS delete the objects in the array and specify to delete the objects
- Zend studio how to import an existing project
- DefCamp Capture the Flag (D-CTF) 2021-22 web
- Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~
- V3_ Chrome extended Chinese translation document V3 directory
- Comprehensively analyze the basic features and summary of free and paid SSH tools
- 2021-05-12
猜你喜欢

Jetpack compose for perfect screen fit

Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~

Shangpinhui knowledge points of large e-commerce projects

MySQL back to table query optimization

Knowledge learned from the water resources institute project

PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available

I love network security for new recruitment assessment

2021-05-12

Laravel upload error

Error $(...) size is not a function
随机推荐
Three uses of golang underscores
Using docker to manage MySQL services under Windows
Jetpack compose for perfect screen fit
Meaning of while (~scanf ("%d%d", & A, & B))
@Component use cases
从控制层返回到js的json数据带“\”转译符,怎么去掉
Introduction to the renewal of substrate source code: the pallet alliance is incorporated into the main line,
About the problems encountered when using the timer class to stop with a button (why does the QPushButton (for the first time) need to be clicked twice to respond?)
Getting started with shell Basics
ThinkPHP show method parameter controllable command execution
Error $(...) size is not a function
Numpy creates an empty array data = np empty(shape=[1, 64,64,3])
2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
Experiment 2: stack
How does hbuilder display in columns?
Summary of use of laravel DCAT admin
Go common lock mutex and rwmutex
Go sync. WaitGroup
DefCamp Capture the Flag (D-CTF) 2021-22 web
Details of gets, fgetc, fgets, Getc, getchar, putc, fputc, putchar, puts, fputs functions