mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
Leetcode day1
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
class Solution {
|
||||
public:
|
||||
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
|
||||
int a = nums1.size();
|
||||
int b = nums2.size();
|
||||
int i=0,j=0,m1=0,m2=0;
|
||||
|
||||
for(int count=0;count<=(a+b)/2;count++){
|
||||
m2=m1;
|
||||
if(i!=a && j!=b){
|
||||
if(nums1[i]<nums2[j]){
|
||||
m1= nums1[i++];
|
||||
}
|
||||
else{
|
||||
m1 = nums2[j++];
|
||||
}
|
||||
}
|
||||
else if(i<a){
|
||||
m1 = nums1[i++];
|
||||
}
|
||||
else {
|
||||
m1 = nums2[j++];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
if((a+b)%2==1){
|
||||
return (double)m1;
|
||||
}
|
||||
else{
|
||||
return (m1+m2)/2.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user