Skip to content

Commit 39208fd

Browse files
authored
Corrected order to ascending (kamyu104#89)
Corrected findKthInSortedArrays to work with k starting from start, not from end. Old version passed all tests also, but now users can reuse this function to really get Kth element in the merged array.
1 parent 885a9d5 commit 39208fd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

C++/median-of-two-sorted-arrays.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ class Solution_Generic {
8484
int res = 0;
8585
for (const auto array : arrays) {
8686
if (!array->empty()) {
87-
res += distance(upper_bound(array->cbegin(), array->cend(), num),
88-
array->cend());
87+
res += distance(array->cbegin(),
88+
upper_bound(array->cbegin(), array->cend(), num));
8989
}
9090
}
91-
return res < target;
91+
return res >= target;
9292
}
9393
};

0 commit comments

Comments
 (0)