Skip to content

Commit

Permalink
Merge pull request #629 from roy2pushkar/dsa
Browse files Browse the repository at this point in the history
Pushkar Roy  Arrays/4.MedianofTwoSortedArray.cpp
  • Loading branch information
gantavyamalviya authored Oct 5, 2022
2 parents 54f3455 + 83ef52a commit 287db41
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Arrays/4.MedianofTwoSortedArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//Name ;- Pushkar Roy
//Date :- 05-10-2022

class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
for(int i=0; i<nums2.size(); i++)
{
nums1.push_back(nums2[i]);
}
sort(nums1.begin(),nums1.end());
if(nums1.size()%2 == 0)
{
return (double(nums1[nums1.size()/2-1] + nums1[nums1.size()/2]))/2;
}
else
{
return float(nums1[nums1.size()/2]);
}
}
};

0 comments on commit 287db41

Please sign in to comment.