diff --git a/Hard/4. Median of Two Sorted Arrays/New approach[Arraylist]/Solution.java b/Hard/4. Median of Two Sorted Arrays/New approach[Arraylist]/Solution.java index cd6969f..8ea97b3 100644 --- a/Hard/4. Median of Two Sorted Arrays/New approach[Arraylist]/Solution.java +++ b/Hard/4. Median of Two Sorted Arrays/New approach[Arraylist]/Solution.java @@ -1,27 +1,42 @@ import java.util.ArrayList; public class Solution{ public double findMedianSortedArrays(int[] nums1, int[] nums2) { - ArrayList list = new ArrayList<>(); //ArrayList Initialization - - //Add Elements from `nums1` to `list` - for(int i:nums1){ - list.add(i); - } - //Add Elements from `nums2` to `list` - for(int j:nums2){ - list.add(j); - } + int a = nums1.length; + int b = nums2.length; - double sum=0; //Initialize a Sum Variable + // Calculate the total length of the merged array + int c = a + b; - for(int i=0;i