commit bb947029b122a93387b985665fbd47717a2b8b3e
parent b46ca7957ef56b5e80afe398c35ea6c6a0735a44
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Mon, 23 Jan 2023 16:39:52 +0100
Data Structure I: Day 2
Diffstat:
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/Problems/0088.cpp b/Problems/0088.cpp
@@ -1,18 +1,10 @@
class Solution {
public:
void merge(vector<int> &nums1, int m, vector<int> &nums2, int n) {
- int i = m - 1;
- int j = n - 1;
- int k = m + n - 1;
+ int i = m - 1, j = n - 1, k = m + n - 1;
while (i >= 0 && j >= 0)
- if (nums1[i] > nums2[j])
- nums1[k--] = nums1[i--];
- else
- nums1[k--] = nums2[j--];
-
- while (i >= 0) nums1[k--] = nums1[i--];
-
+ nums1[k--] = nums1[i] > nums2[j] ? nums1[i--] : nums2[j--];
while (j >= 0) nums1[k--] = nums2[j--];
}
};