My LeetCode grinding. Trying to do a problem a day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 602B

123456789101112131415161718192021222324
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. void merge(std::vector<int>& nums1, int m, std::vector<int>& nums2, int n) {
  5. int total = m + n;
  6. while (n > 0) {
  7. nums1[m++] = nums2[--n];
  8. }
  9. std::sort(nums1.begin(), nums1.end());
  10. }
  11. int main() {
  12. std::cout << "Expected: [1, 2, 2, 3, 5, 6]" << std::endl;
  13. std::vector<int> n1 = {1, 2, 3, 0, 0, 0};
  14. std::vector<int> n2 = {2, 5, 6};
  15. merge(n1, 3, n2, 3);
  16. std::cout << "Got: [ ";
  17. for (int i = 0; i < 6; i++) {
  18. std::cout << n1[i] << " ";
  19. }
  20. std::cout << " ]" << std::endl;
  21. return 0;
  22. }