Skip to content

Commit

Permalink
Expand MergeSortedArray conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
huangsam committed Nov 11, 2024
1 parent d966249 commit 3ba97c6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions java/MergeSortedArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ public void merge(int[] nums1, int m, int[] nums2, int n) {
int secondIndex = n - 1;
int mergeIndex = m + n - 1;
while (secondIndex >= 0) {
nums1[mergeIndex--] = (firstIndex >= 0 && nums1[firstIndex] > nums2[secondIndex])
? nums1[firstIndex--]
: nums2[secondIndex--];
if (firstIndex >= 0 && nums1[firstIndex] > nums2[secondIndex]) {
nums1[mergeIndex--] = nums1[firstIndex--];
} else {
nums1[mergeIndex--] = nums2[secondIndex--];
}
}
}
}

0 comments on commit 3ba97c6

Please sign in to comment.