0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Leetcode Easy 88. Merge Sorted Array

Posted at

Vectorを結合してソートする問題。

using namespace std;
# include <iostream>
# include <algorithm>
# include <vector>
# include <random>
class Solution {
    public:
        void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
            vector<int> ans;
            for (int i = 0; i < n; i++) {
                nums1[m+i] = nums2[i];
            }
            sort(nums1.begin(), nums1.begin() + m + n);

            //確認用
            for (int i = 0; i < n + m; i++) cout << i << " " << endl;
        }

};

int main()
{
    Solution* Sol = new Solution();
    random_device rnd;
    mt19937 mt(rnd());

    vector<int> v1(300);
    for (int i = 0; i < 100; ++i) v1[i] = (mt() % 1000);

    cout << endl;
    vector<int> v2(100);
    for (int i = 0; i < 100; ++i) v2[i] = mt() % 1000;

    Sol->merge(v1,100, v2,v2.size());
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?