#Leetcode Problem no. 88 | Merge Sorted Array

3 messages · Page 1 of 1 (latest)

earnest sorrel
#
class Solution {
public:
    void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
        int i = 0;
        int j = 0;
        int k = 0;
        while (i < m && j < n) {
            if (nums1[i] < nums2[j]) {
                nums1[k++] = nums1[i++];

            } else {
                nums1[k++] = nums2[j++];
            }
        }
        while (i < m) {
            nums1[k++] = nums1[i++];
        }
        while (j < n) {
            nums1[k++] = nums2[j++];
        }
    }
};

What is the wrong in my code. It only shows error in the first test case.

real kiteBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

earnest sorrel
#

Leetcode Problem no. 88 | Merge Sorted Array