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