We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e92af89 commit da264caCopy full SHA for da264ca
4.cpp
@@ -0,0 +1,49 @@
1
+class Solution {
2
+public:
3
+ double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
4
+ int m = nums1.size();
5
+ int n = nums2.size();
6
+
7
+ int C[m+n];
8
+ int i = 0;
9
+ int j = 0;
10
+ int k = 0;
11
12
+ while(i < m && j < n)
13
+ {
14
+ if(nums1[i] <= nums2[j])
15
16
+ C[k++] = nums1[i++];
17
+ }
18
+ else
19
20
+ C[k++] = nums2[j++];
21
22
23
24
+ if(i == m)
25
26
+ while( j < n )
27
28
29
30
31
32
33
+ while( i < m )
34
35
36
37
38
39
+ k = n + m;
40
+ if( k % 2 == 0)
41
42
+ return (C[k/2] + C[k/2 - 1])/2.0;
43
44
45
46
+ return C[k/2];
47
48
49
+};
0 commit comments