Leetcode 88 Solution
This article provides solution to leetcode question 88 (merge-sorted-array)
Access this page by simply typing in "lcs 88" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/merge-sorted-array
Solution
class Solution {
public:
void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
int l = nums1.size() - 1;
m = m - 1;
n = n - 1;
for (; l >= 0;)
{
int val = INT_MIN;
if (m >= 0 && n >= 0)
{
if (nums1[m] < nums2[n])
{
nums1[l--] = nums2[n--];
}
else
{
nums1[l--] = nums1[m--];
}
}
else if (m >= 0)
nums1[l--] = nums1[m--];
else if (n >= 0)
nums1[l--] = nums2[n--];
}
}
};