- python3 (preferably >3.8) | - python3 (preferably >3.8) | ||||
- rustc | - rustc | ||||
- gcc | - gcc | ||||
- g++ | |||||
Then you can see all the problems go through an example case with: | Then you can see all the problems go through an example case with: | ||||
#include <vector> | |||||
#include <iostream> | |||||
#include <algorithm> | |||||
void merge(std::vector<int>& nums1, int m, std::vector<int>& nums2, int n) { | |||||
int total = m + n; | |||||
while (n > 0) { | |||||
nums1[m++] = nums2[--n]; | |||||
} | |||||
std::sort(nums1.begin(), nums1.end()); | |||||
} | |||||
int main() { | |||||
std::cout << "Expected: [1, 2, 2, 3, 5, 6]" << std::endl; | |||||
std::vector<int> n1 = {1, 2, 3, 0, 0, 0}; | |||||
std::vector<int> n2 = {2, 5, 6}; | |||||
merge(n1, 3, n2, 3); | |||||
std::cout << "Got: [ "; | |||||
for (int i = 0; i < 6; i++) { | |||||
std::cout << n1[i] << " "; | |||||
} | |||||
std::cout << " ]" << std::endl; | |||||
return 0; | |||||
} |
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. | |||||
Note: | |||||
The number of elements initialized in nums1 and nums2 are m and n respectively. | |||||
You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. | |||||
Example: | |||||
Input: | |||||
nums1 = [1,2,3,0,0,0], m = 3 | |||||
nums2 = [2,5,6], n = 3 | |||||
Output: [1,2,2,3,5,6] | |||||
#!/bin/bash | |||||
g++ -o main main.cpp | |||||
./main | |||||
rm main |