【LeetCode 88_数组】Merge Sorted Array

 1 void merge(vector<int>& nums1, int m, vector<int>& nums2, int n)
 2 {
 3     int i = m - 1;
 4     int j = n - 1;
 5     int k = m + n - 1;
 6     while (i >=0 && j >= 0) {
 7         if (nums1[i] > nums2[j])
 8             nums1[k--] = nums1[i--];
 9         else
10             nums1[k--] = nums2[j--];
11     }
12     while (j >= 0)
13         nums1[k--] = nums2[j--];
14
15 }
时间: 2024-11-06 09:58:17

【LeetCode 88_数组】Merge Sorted Array的相关文章

leetcode 题解:Merge Sorted Array(两个已排序数组归并)

题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B ar

归并有序数组--Merge Sorted Array

https://leetcode.com/problems/merge-sorted-array/ Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n)

LeetCode OJ:Merge Sorted Array(合并排序的数组)

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initi

【一天一道LeetCode】#88. Merge Sorted Array

一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is g

88. 合并两个已排序的数组 Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initi

Leetcode题目:Merge Sorted Array

题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements i

高效合并两个有序数组(Merge Sorted Array)

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.The number of elements initi

leetcode || 88、Merge Sorted Array

problem: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A an

LeetCode(88)题解-- Merge Sorted Array

https://leetcode.com/problems/merge-sorted-array/ 题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additi

LeetCode 88:Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements init