@@ -353,30 +353,30 @@ proc medianOfTwoSortedArrays(nums1: seq[int], nums2: seq[int]): float =
353
353
#### C
354
354
355
355
``` c
356
- int findKth (int * nums1, int m, int i, int * nums2, int n, int j, int k) {
357
- if (i >= m)
358
- return nums2[ j + k - 1] ;
359
- if (j >= n)
360
- return nums1[ i + k - 1] ;
361
- if (k == 1)
362
- return nums1[ i] < nums2[ j] ? nums1[ i] : nums2[ j] ;
363
-
364
- int p = k / 2;
365
-
366
- int x = (i + p - 1 < m) ? nums1[ i + p - 1] : INT_MAX;
367
- int y = (j + p - 1 < n) ? nums2[ j + p - 1] : INT_MAX;
368
-
369
- if (x < y)
370
- return findKth(nums1, m, i + p, nums2, n, j, k - p);
371
- else
372
- return findKth(nums1, m, i, nums2, n, j + p, k - p);
356
+ int findKth (int* nums1, int m, int i, int* nums2, int n, int j, int k) {
357
+ if (i >= m)
358
+ return nums2[ j + k - 1] ;
359
+ if (j >= n)
360
+ return nums1[ i + k - 1] ;
361
+ if (k == 1)
362
+ return nums1[ i] < nums2[ j] ? nums1[ i] : nums2[ j] ;
363
+
364
+ int p = k / 2;
365
+
366
+ int x = (i + p - 1 < m) ? nums1[i + p - 1] : INT_MAX;
367
+ int y = (j + p - 1 < n) ? nums2[j + p - 1] : INT_MAX;
368
+
369
+ if (x < y)
370
+ return findKth(nums1, m, i + p, nums2, n, j, k - p);
371
+ else
372
+ return findKth(nums1, m, i, nums2, n, j + p, k - p);
373
373
}
374
374
375
- double findMedianSortedArrays(int * nums1, int m, int * nums2, int n) {
376
- int total = m + n;
377
- int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
378
- int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
379
- return (a + b) / 2.0;
375
+ double findMedianSortedArrays(int* nums1, int m, int* nums2, int n) {
376
+ int total = m + n;
377
+ int a = findKth(nums1, m, 0, nums2, n, 0, (total + 1) / 2);
378
+ int b = findKth(nums1, m, 0, nums2, n, 0, (total + 2) / 2);
379
+ return (a + b) / 2.0;
380
380
}
381
381
```
382
382
0 commit comments